Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Unified Diff: content/browser/service_worker/service_worker_browsertest.cc

Issue 434453005: test for https://codereview.chromium.org/419693002/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_browsertest.cc
diff --git a/content/browser/service_worker/service_worker_browsertest.cc b/content/browser/service_worker/service_worker_browsertest.cc
index 0ae1341d7eb69bc50142a08bfcef1075f8f1e835..7791284ea55941cc1e83cadab14338763402e084 100644
--- a/content/browser/service_worker/service_worker_browsertest.cc
+++ b/content/browser/service_worker/service_worker_browsertest.cc
@@ -25,6 +25,7 @@
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
+#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
@@ -699,6 +700,56 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, DISABLED_Reload) {
}
}
+static void CountScriptResources(
+ ServiceWorkerContextWrapper* wrapper,
+ const GURL& scope,
+ int* num_resource_out) {
+ *num_resource_out = -1;
dominicc (has gone to gerrit) 2014/08/04 01:27:10 I think you want a plural instead of "resource"?
michaeln 2014/08/08 02:32:37 Done.
+
+ std::vector<ServiceWorkerRegistrationInfo> infos =
dominicc (has gone to gerrit) 2014/08/04 01:27:09 Maybe "registrations" reads more easily than "info
michaeln 2014/08/08 02:32:37 there is a good convention for calling structs lik
dominicc (has gone to gerrit) 2014/08/08 05:23:38 Acknowledged.
+ wrapper->context()->GetAllLiveRegistrationInfo();
+ if (infos.empty())
+ return;
+
+ int version_id;
+ size_t index = infos.size();
+ if (!infos[index].installing_version.is_null)
dominicc (has gone to gerrit) 2014/08/04 01:27:09 Don't vectors index from 0?
michaeln 2014/08/08 02:32:37 I googled it, yes they do.
dominicc (has gone to gerrit) 2014/08/08 05:23:38 So isn't infos[infos.size()] out of bounds?
+ version_id = infos[index].installing_version.version_id;
+ else if (!infos[index].waiting_version.is_null)
+ version_id = infos[1].waiting_version.version_id;
+ else if (!infos[index].active_version.is_null)
+ version_id = infos[index].active_version.version_id;
+ else
+ return;
+
+ ServiceWorkerVersion* version =
+ wrapper->context()->GetLiveVersion(version_id);
+ *num_resource_out = static_cast<int>(version->script_cache_map()->size());
+}
+
+IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, ImportsBustMemcache) {
+ const std::string kScopeUrl = "/service_worker/imports_bust_memcache_scope/*";
dominicc (has gone to gerrit) 2014/08/04 01:27:10 I think a change has landed that updates the handl
michaeln 2014/08/08 02:32:37 Done.
+ const std::string kPageUrl = "/service_worker/imports_bust_memcache.html";
+ const base::string16 kOKTitle(base::ASCIIToUTF16("OK"));
+ const base::string16 kFailTitle(base::ASCIIToUTF16("FAIL"));
+
+ TitleWatcher title_watcher(shell()->web_contents(), kOKTitle);
+ title_watcher.AlsoWaitForTitle(kFailTitle);
+ NavigateToURL(shell(), embedded_test_server()->GetURL(kPageUrl));
+ base::string16 title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(kOKTitle, title);
+
+ // Verify the number of resources in the implicit script cache is correct.
+ const size_t kExpectedNumResources = 2u;
+ int num_resources = 0;
+ RunOnIOThread(
+ base::Bind(&CountScriptResources,
+ base::Unretained(wrapper()),
+ embedded_test_server()->GetURL(kScopeUrl),
+ &num_resources));
+ EXPECT_EQ(kExpectedNumResources, num_resources);
+}
+
class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest {
public:
typedef ServiceWorkerBlackBoxBrowserTest self;

Powered by Google App Engine
This is Rietveld 408576698