1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Merge branch 'offline_application_cache' of git://github.com/betelgeuse/capybara-webkit

This commit is contained in:
Matthew Horan 2014-08-18 12:25:49 -04:00
commit 88c2596fb0
4 changed files with 87 additions and 0 deletions

View file

@ -82,6 +82,13 @@ If you're using capybara-webkit with Sinatra, don't forget to set
Capybara.app = MySinatraApp.new
```
Offline Application Cache
-------------------------
The offline application cache needs a directory to write to for the cached files. Capybara-webkit
will look at if the working directory has a tmp directory and when it exists offline application
cache will be enabled.
Non-Standard Driver Methods
---------------------------

View file

@ -2025,6 +2025,75 @@ describe Capybara::Webkit::Driver do
end
end
context "offline application cache" do
let(:driver) do
@visited = []
visited = @visited
driver_for_app do
get '/8d853f09-4275-409d-954d-ebbf6e2ce732' do
content_type 'text/cache-manifest'
visited << 'manifest'
<<-TEXT
CACHE MANIFEST
/4aaffa31-f42d-403e-a19e-6b248d608087
TEXT
end
# UUID urls so that this gets isolated from other tests
get '/f8742c39-8bef-4196-b1c3-80f8a3d65f3e' do
visited << 'complex'
<<-HTML
<html manifest="/8d853f09-4275-409d-954d-ebbf6e2ce732">
<body>
<span id='state'></span>
<span id='finished'></span>
<script type="text/javascript">
document.getElementById("state").innerHTML = applicationCache.status;
applicationCache.addEventListener('cached', function() {
document.getElementById("finished").innerHTML = 'cached';
});
applicationCache.addEventListener('error', function() {
document.getElementById("finished").innerHTML = 'error';
});
</script>
</body>
</html>
HTML
end
get '/4aaffa31-f42d-403e-a19e-6b248d608087' do
visited << 'simple'
<<-HTML
<html manifest="/8d853f09-4275-409d-954d-ebbf6e2ce732">
<body>
</body>
</html>
HTML
end
end
end
before { visit("/f8742c39-8bef-4196-b1c3-80f8a3d65f3e") }
it "has proper state available" do
driver.find_xpath("//*[@id='state']").first.visible_text.should == '0'
sleep 1
@visited.should eq(['complex', 'manifest', 'simple']), 'files were not downloaded in expected order'
driver.find_xpath("//*[@id='finished']").first.visible_text.should == 'cached'
end
it "is cleared on driver reset!" do
sleep 1
@visited.should eq(['complex', 'manifest', 'simple']), 'files were not downloaded in expected order'
driver.reset!
@visited.clear
visit '/4aaffa31-f42d-403e-a19e-6b248d608087'
sleep 1
@visited.should eq(['simple', 'manifest', 'simple']), 'simple action was used from cache instead of server'
end
end
context "form app with server-side handler" do
let(:driver) do
driver_for_app do

View file

@ -40,6 +40,11 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
if(QFileInfo("tmp").isDir()) {
settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
settings()->setOfflineWebApplicationCachePath("tmp");
}
createWindow();
}

View file

@ -124,6 +124,12 @@ void WebPageManager::reset() {
WebPage *page = m_pages.takeFirst();
page->deleteLater();
}
qint64 size = QWebSettings::offlineWebApplicationCacheQuota();
// No public function was found to wrap the empty() call to
// WebCore::cacheStorage().empty()
QWebSettings::setOfflineWebApplicationCacheQuota(size);
createPage()->setFocus();
}