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

Side by Side Diff: chrome/browser/chrome_service_worker_browsertest.cc

Issue 2317993003: //chrome/browser and //components A-E: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file tests that Service Workers (a Content feature) work in the Chromium 5 // This file tests that Service Workers (a Content feature) work in the Chromium
6 // embedder. 6 // embedder.
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 27 matching lines...) Expand all
38 class ChromeServiceWorkerTest : public InProcessBrowserTest { 38 class ChromeServiceWorkerTest : public InProcessBrowserTest {
39 protected: 39 protected:
40 ChromeServiceWorkerTest() { 40 ChromeServiceWorkerTest() {
41 EXPECT_TRUE(service_worker_dir_.CreateUniqueTempDir()); 41 EXPECT_TRUE(service_worker_dir_.CreateUniqueTempDir());
42 } 42 }
43 ~ChromeServiceWorkerTest() override {} 43 ~ChromeServiceWorkerTest() override {}
44 44
45 void WriteFile(const base::FilePath::StringType& filename, 45 void WriteFile(const base::FilePath::StringType& filename,
46 base::StringPiece contents) { 46 base::StringPiece contents) {
47 EXPECT_EQ(base::checked_cast<int>(contents.size()), 47 EXPECT_EQ(base::checked_cast<int>(contents.size()),
48 base::WriteFile(service_worker_dir_.path().Append(filename), 48 base::WriteFile(service_worker_dir_.GetPath().Append(filename),
49 contents.data(), 49 contents.data(), contents.size()));
50 contents.size()));
51 } 50 }
52 51
53 base::ScopedTempDir service_worker_dir_; 52 base::ScopedTempDir service_worker_dir_;
54 53
55 private: 54 private:
56 DISALLOW_COPY_AND_ASSIGN(ChromeServiceWorkerTest); 55 DISALLOW_COPY_AND_ASSIGN(ChromeServiceWorkerTest);
57 }; 56 };
58 57
59 static void ExpectResultAndRun(bool expected, 58 static void ExpectResultAndRun(bool expected,
60 const base::Closure& continuation, 59 const base::Closure& continuation,
61 bool actual) { 60 bool actual) {
62 EXPECT_EQ(expected, actual); 61 EXPECT_EQ(expected, actual);
63 continuation.Run(); 62 continuation.Run();
64 } 63 }
65 64
66 // http://crbug.com/368570 65 // http://crbug.com/368570
67 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, 66 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest,
68 CanShutDownWithRegisteredServiceWorker) { 67 CanShutDownWithRegisteredServiceWorker) {
69 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); 68 WriteFile(FILE_PATH_LITERAL("service_worker.js"), "");
70 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), 69 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"),
71 "HTTP/1.1 200 OK\nContent-Type: text/javascript"); 70 "HTTP/1.1 200 OK\nContent-Type: text/javascript");
72 71
73 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); 72 embedded_test_server()->ServeFilesFromDirectory(
73 service_worker_dir_.GetPath());
74 ASSERT_TRUE(embedded_test_server()->Start()); 74 ASSERT_TRUE(embedded_test_server()->Start());
75 75
76 content::ServiceWorkerContext* sw_context = 76 content::ServiceWorkerContext* sw_context =
77 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) 77 content::BrowserContext::GetDefaultStoragePartition(browser()->profile())
78 ->GetServiceWorkerContext(); 78 ->GetServiceWorkerContext();
79 79
80 base::RunLoop run_loop; 80 base::RunLoop run_loop;
81 sw_context->RegisterServiceWorker( 81 sw_context->RegisterServiceWorker(
82 embedded_test_server()->GetURL("/"), 82 embedded_test_server()->GetURL("/"),
83 embedded_test_server()->GetURL("/service_worker.js"), 83 embedded_test_server()->GetURL("/service_worker.js"),
84 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); 84 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
85 run_loop.Run(); 85 run_loop.Run();
86 86
87 // Leave the Service Worker registered, and make sure that the browser can 87 // Leave the Service Worker registered, and make sure that the browser can
88 // shut down without DCHECK'ing. It'd be nice to check here that the SW is 88 // shut down without DCHECK'ing. It'd be nice to check here that the SW is
89 // actually occupying a process, but we don't yet have the public interface to 89 // actually occupying a process, but we don't yet have the public interface to
90 // do that. 90 // do that.
91 } 91 }
92 92
93 // http://crbug.com/419290 93 // http://crbug.com/419290
94 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest, 94 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerTest,
95 CanCloseIncognitoWindowWithServiceWorkerController) { 95 CanCloseIncognitoWindowWithServiceWorkerController) {
96 WriteFile(FILE_PATH_LITERAL("service_worker.js"), ""); 96 WriteFile(FILE_PATH_LITERAL("service_worker.js"), "");
97 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"), 97 WriteFile(FILE_PATH_LITERAL("service_worker.js.mock-http-headers"),
98 "HTTP/1.1 200 OK\nContent-Type: text/javascript"); 98 "HTTP/1.1 200 OK\nContent-Type: text/javascript");
99 WriteFile(FILE_PATH_LITERAL("test.html"), ""); 99 WriteFile(FILE_PATH_LITERAL("test.html"), "");
100 100
101 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); 101 embedded_test_server()->ServeFilesFromDirectory(
102 service_worker_dir_.GetPath());
102 ASSERT_TRUE(embedded_test_server()->Start()); 103 ASSERT_TRUE(embedded_test_server()->Start());
103 104
104 Browser* incognito = CreateIncognitoBrowser(); 105 Browser* incognito = CreateIncognitoBrowser();
105 content::ServiceWorkerContext* sw_context = 106 content::ServiceWorkerContext* sw_context =
106 content::BrowserContext::GetDefaultStoragePartition(incognito->profile()) 107 content::BrowserContext::GetDefaultStoragePartition(incognito->profile())
107 ->GetServiceWorkerContext(); 108 ->GetServiceWorkerContext();
108 109
109 base::RunLoop run_loop; 110 base::RunLoop run_loop;
110 sw_context->RegisterServiceWorker( 111 sw_context->RegisterServiceWorker(
111 embedded_test_server()->GetURL("/"), 112 embedded_test_server()->GetURL("/"),
(...skipping 12 matching lines...) Expand all
124 // Test passes if we don't crash. 125 // Test passes if we don't crash.
125 } 126 }
126 127
127 class ChromeServiceWorkerFetchTest : public ChromeServiceWorkerTest { 128 class ChromeServiceWorkerFetchTest : public ChromeServiceWorkerTest {
128 protected: 129 protected:
129 ChromeServiceWorkerFetchTest() {} 130 ChromeServiceWorkerFetchTest() {}
130 ~ChromeServiceWorkerFetchTest() override {} 131 ~ChromeServiceWorkerFetchTest() override {}
131 132
132 void SetUpOnMainThread() override { 133 void SetUpOnMainThread() override {
133 WriteServiceWorkerFetchTestFiles(); 134 WriteServiceWorkerFetchTestFiles();
134 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); 135 embedded_test_server()->ServeFilesFromDirectory(
136 service_worker_dir_.GetPath());
135 ASSERT_TRUE(embedded_test_server()->Start()); 137 ASSERT_TRUE(embedded_test_server()->Start());
136 InitializeServiceWorkerFetchTestPage(); 138 InitializeServiceWorkerFetchTestPage();
137 } 139 }
138 140
139 std::string ExecuteScriptAndExtractString(const std::string& js) { 141 std::string ExecuteScriptAndExtractString(const std::string& js) {
140 std::string result; 142 std::string result;
141 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 143 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
142 browser()->tab_strip_model()->GetActiveWebContents(), js, &result)); 144 browser()->tab_strip_model()->GetActiveWebContents(), js, &result));
143 return result; 145 return result;
144 } 146 }
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 " if (worker.state == 'activated')" 556 " if (worker.state == 'activated')"
555 " document.title = 'READY';" 557 " document.title = 'READY';"
556 " });" 558 " });"
557 " });" 559 " });"
558 " });" 560 " });"
559 "</script>" 561 "</script>"
560 "<body style='margin:0; padding:0;'>" 562 "<body style='margin:0; padding:0;'>"
561 "<a href='./scope/' style='position:fixed; width:1px; height:1px;'></a>" 563 "<a href='./scope/' style='position:fixed; width:1px; height:1px;'></a>"
562 "</body>"); 564 "</body>");
563 565
564 embedded_test_server()->ServeFilesFromDirectory(service_worker_dir_.path()); 566 embedded_test_server()->ServeFilesFromDirectory(
567 service_worker_dir_.GetPath());
565 ASSERT_TRUE(embedded_test_server()->Start()); 568 ASSERT_TRUE(embedded_test_server()->Start());
566 569
567 content::ServiceWorkerContext* sw_context = 570 content::ServiceWorkerContext* sw_context =
568 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()) 571 content::BrowserContext::GetDefaultStoragePartition(browser()->profile())
569 ->GetServiceWorkerContext(); 572 ->GetServiceWorkerContext();
570 573
571 const base::string16 expected_title1 = base::ASCIIToUTF16("READY"); 574 const base::string16 expected_title1 = base::ASCIIToUTF16("READY");
572 content::TitleWatcher title_watcher1( 575 content::TitleWatcher title_watcher1(
573 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1); 576 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1);
574 ui_test_utils::NavigateToURL(browser(), 577 ui_test_utils::NavigateToURL(browser(),
(...skipping 20 matching lines...) Expand all
595 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); 598 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
596 599
597 // The service worker must be started by a navigation hint. 600 // The service worker must be started by a navigation hint.
598 histogram_tester_.ExpectBucketCount( 601 histogram_tester_.ExpectBucketCount(
599 "ServiceWorker.StartWorker.StatusByPurpose_NAVIGATION_HINT_LINK_MOUSE_" 602 "ServiceWorker.StartWorker.StatusByPurpose_NAVIGATION_HINT_LINK_MOUSE_"
600 "DOWN", 603 "DOWN",
601 0 /* SERVICE_WORKER_OK */, 1); 604 0 /* SERVICE_WORKER_OK */, 1);
602 } 605 }
603 606
604 } // namespace 607 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698