OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
13 #include "content/browser/background_sync/background_sync_manager.h" | 13 #include "content/browser/background_sync/background_sync_manager.h" |
14 #include "content/browser/background_sync/background_sync_network_observer.h" | 14 #include "content/browser/background_sync/background_sync_network_observer.h" |
15 #include "content/browser/background_sync/background_sync_registration_handle.h" | 15 #include "content/browser/background_sync/background_sync_registration_handle.h" |
16 #include "content/browser/background_sync/background_sync_status.h" | 16 #include "content/browser/background_sync/background_sync_status.h" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/browser/service_worker/service_worker_registration.h" | 18 #include "content/browser/service_worker/service_worker_registration.h" |
19 #include "content/public/browser/background_sync_context.h" | 19 #include "content/public/browser/background_sync_context.h" |
20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
21 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
25 #include "content/public/test/content_browser_test.h" | 25 #include "content/public/test/content_browser_test.h" |
26 #include "content/public/test/content_browser_test_utils.h" | 26 #include "content/public/test/content_browser_test_utils.h" |
27 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
28 #include "content/shell/browser/shell.h" | 28 #include "content/shell/browser/shell.h" |
29 #include "net/base/network_change_notifier.h" | 29 #include "net/base/network_change_notifier.h" |
| 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 using net::NetworkChangeNotifier; | 33 using net::NetworkChangeNotifier; |
33 | 34 |
34 namespace content { | 35 namespace content { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 const char kDefaultTestURL[] = "files/background_sync/test.html"; | 39 const char kDefaultTestURL[] = "/background_sync/test.html"; |
39 | 40 |
40 const char kSuccessfulOperationPrefix[] = "ok - "; | 41 const char kSuccessfulOperationPrefix[] = "ok - "; |
41 | 42 |
42 std::string BuildScriptString(const std::string& function, | 43 std::string BuildScriptString(const std::string& function, |
43 const std::string& argument) { | 44 const std::string& argument) { |
44 return base::StringPrintf("%s('%s');", function.c_str(), argument.c_str()); | 45 return base::StringPrintf("%s('%s');", function.c_str(), argument.c_str()); |
45 } | 46 } |
46 | 47 |
47 std::string BuildExpectedResult(const std::string& tag, | 48 std::string BuildExpectedResult(const std::string& tag, |
48 const std::string& action) { | 49 const std::string& action) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 121 } |
121 | 122 |
122 void SetUpCommandLine(base::CommandLine* command_line) override { | 123 void SetUpCommandLine(base::CommandLine* command_line) override { |
123 // TODO(jkarlin): Remove this once background sync is no longer | 124 // TODO(jkarlin): Remove this once background sync is no longer |
124 // experimental. | 125 // experimental. |
125 command_line->AppendSwitch( | 126 command_line->AppendSwitch( |
126 switches::kEnableExperimentalWebPlatformFeatures); | 127 switches::kEnableExperimentalWebPlatformFeatures); |
127 } | 128 } |
128 | 129 |
129 void SetUpOnMainThread() override { | 130 void SetUpOnMainThread() override { |
130 https_server_.reset(new net::SpawnedTestServer( | 131 https_server_.reset( |
131 net::SpawnedTestServer::TYPE_HTTPS, | 132 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
132 net::BaseTestServer::SSLOptions( | 133 https_server_->ServeFilesFromSourceDirectory("content/test/data"); |
133 net::BaseTestServer::SSLOptions::CERT_OK), | |
134 base::FilePath(FILE_PATH_LITERAL("content/test/data/")))); | |
135 ASSERT_TRUE(https_server_->Start()); | 134 ASSERT_TRUE(https_server_->Start()); |
136 | 135 |
137 SetIncognitoMode(false); | 136 SetIncognitoMode(false); |
138 | 137 |
139 SetOnline(true); | 138 SetOnline(true); |
140 | 139 |
141 ASSERT_TRUE(LoadTestPage(kDefaultTestURL)); | 140 ASSERT_TRUE(LoadTestPage(kDefaultTestURL)); |
142 | 141 |
143 ContentBrowserTest::SetUpOnMainThread(); | 142 ContentBrowserTest::SetUpOnMainThread(); |
144 } | 143 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); | 181 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); |
183 bool GetRegistrationsOneShotFromServiceWorker( | 182 bool GetRegistrationsOneShotFromServiceWorker( |
184 const std::vector<std::string>& expected_tags); | 183 const std::vector<std::string>& expected_tags); |
185 bool CompleteDelayedOneShot(); | 184 bool CompleteDelayedOneShot(); |
186 bool RejectDelayedOneShot(); | 185 bool RejectDelayedOneShot(); |
187 bool NotifyWhenFinishedOneShot(const std::string& tag); | 186 bool NotifyWhenFinishedOneShot(const std::string& tag); |
188 bool NotifyWhenFinishedImmediateOneShot(const std::string& expected_msg); | 187 bool NotifyWhenFinishedImmediateOneShot(const std::string& expected_msg); |
189 bool StoreRegistrationOneShot(const std::string& tag); | 188 bool StoreRegistrationOneShot(const std::string& tag); |
190 | 189 |
191 private: | 190 private: |
192 scoped_ptr<net::SpawnedTestServer> https_server_; | 191 scoped_ptr<net::EmbeddedTestServer> https_server_; |
193 Shell* shell_ = nullptr; | 192 Shell* shell_ = nullptr; |
194 | 193 |
195 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); | 194 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); |
196 }; | 195 }; |
197 | 196 |
198 void BackgroundSyncBrowserTest::SetOnline(bool online) { | 197 void BackgroundSyncBrowserTest::SetOnline(bool online) { |
199 ASSERT_TRUE(shell_); | 198 ASSERT_TRUE(shell_); |
200 BrowserThread::PostTask( | 199 BrowserThread::PostTask( |
201 BrowserThread::IO, FROM_HERE, | 200 BrowserThread::IO, FROM_HERE, |
202 base::Bind(&BackgroundSyncBrowserTest::SetOnlineOnIOThread, | 201 base::Bind(&BackgroundSyncBrowserTest::SetOnlineOnIOThread, |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 | 752 |
754 // Simulate a user clearing site data (including Service Workers, crucially), | 753 // Simulate a user clearing site data (including Service Workers, crucially), |
755 // by clearing data from the storage partition. | 754 // by clearing data from the storage partition. |
756 ClearStoragePartitionData(); | 755 ClearStoragePartitionData(); |
757 | 756 |
758 // Verify that it was deleted. | 757 // Verify that it was deleted. |
759 EXPECT_FALSE(GetRegistrationOneShot("delay")); | 758 EXPECT_FALSE(GetRegistrationOneShot("delay")); |
760 } | 759 } |
761 | 760 |
762 } // namespace content | 761 } // namespace content |
OLD | NEW |