| OLD | NEW |
| 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 #include <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 WebContents* web_contents_; | 45 WebContents* web_contents_; |
| 46 ManifestBrowserTest* test_; | 46 ManifestBrowserTest* test_; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class ManifestBrowserTest : public ContentBrowserTest { | 49 class ManifestBrowserTest : public ContentBrowserTest { |
| 50 protected: | 50 protected: |
| 51 friend MockWebContentsDelegate; | 51 friend MockWebContentsDelegate; |
| 52 | 52 |
| 53 ManifestBrowserTest() : console_error_count_(0), has_manifest_(false) { | 53 ManifestBrowserTest() : console_error_count_(0) { |
| 54 cors_embedded_test_server_.reset(new net::EmbeddedTestServer); | 54 cors_embedded_test_server_.reset(new net::EmbeddedTestServer); |
| 55 cors_embedded_test_server_->ServeFilesFromSourceDirectory( | 55 cors_embedded_test_server_->ServeFilesFromSourceDirectory( |
| 56 "content/test/data"); | 56 "content/test/data"); |
| 57 } | 57 } |
| 58 | 58 |
| 59 ~ManifestBrowserTest() override {} | 59 ~ManifestBrowserTest() override {} |
| 60 | 60 |
| 61 void SetUpOnMainThread() override { | 61 void SetUpOnMainThread() override { |
| 62 ContentBrowserTest::SetUpOnMainThread(); | 62 ContentBrowserTest::SetUpOnMainThread(); |
| 63 DCHECK(shell()->web_contents()); | 63 DCHECK(shell()->web_contents()); |
| 64 | 64 |
| 65 mock_web_contents_delegate_.reset( | 65 mock_web_contents_delegate_.reset( |
| 66 new MockWebContentsDelegate(shell()->web_contents(), this)); | 66 new MockWebContentsDelegate(shell()->web_contents(), this)); |
| 67 shell()->web_contents()->SetDelegate(mock_web_contents_delegate_.get()); | 67 shell()->web_contents()->SetDelegate(mock_web_contents_delegate_.get()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void GetManifestAndWait() { | 70 void GetManifestAndWait() { |
| 71 shell()->web_contents()->GetManifest( | 71 shell()->web_contents()->GetManifest( |
| 72 base::Bind(&ManifestBrowserTest::OnGetManifest, | 72 base::Bind(&ManifestBrowserTest::OnGetManifest, |
| 73 base::Unretained(this))); | 73 base::Unretained(this))); |
| 74 | 74 |
| 75 message_loop_runner_ = new MessageLoopRunner(); | 75 message_loop_runner_ = new MessageLoopRunner(); |
| 76 message_loop_runner_->Run(); | 76 message_loop_runner_->Run(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void HasManifestAndWait() { | |
| 80 shell()->web_contents()->HasManifest( | |
| 81 base::Bind(&ManifestBrowserTest::OnHasManifest, | |
| 82 base::Unretained(this))); | |
| 83 | |
| 84 message_loop_runner_ = new MessageLoopRunner(); | |
| 85 message_loop_runner_->Run(); | |
| 86 } | |
| 87 | |
| 88 void OnGetManifest(const GURL& manifest_url, const Manifest& manifest) { | 79 void OnGetManifest(const GURL& manifest_url, const Manifest& manifest) { |
| 80 manifest_url_ = manifest_url; |
| 89 manifest_ = manifest; | 81 manifest_ = manifest; |
| 90 message_loop_runner_->Quit(); | 82 message_loop_runner_->Quit(); |
| 91 } | 83 } |
| 92 | 84 |
| 93 void OnHasManifest(bool has_manifest) { | |
| 94 has_manifest_ = has_manifest; | |
| 95 message_loop_runner_->Quit(); | |
| 96 } | |
| 97 | |
| 98 const Manifest& manifest() const { | 85 const Manifest& manifest() const { |
| 99 return manifest_; | 86 return manifest_; |
| 100 } | 87 } |
| 101 | 88 |
| 102 bool has_manifest() const { | 89 const GURL& manifest_url() const { |
| 103 return has_manifest_; | 90 return manifest_url_; |
| 104 } | 91 } |
| 105 | 92 |
| 106 unsigned int console_error_count() const { | 93 unsigned int console_error_count() const { |
| 107 return console_error_count_; | 94 return console_error_count_; |
| 108 } | 95 } |
| 109 | 96 |
| 110 void OnReceivedConsoleError() { | 97 void OnReceivedConsoleError() { |
| 111 console_error_count_++; | 98 console_error_count_++; |
| 112 } | 99 } |
| 113 | 100 |
| 114 net::EmbeddedTestServer* cors_embedded_test_server() const { | 101 net::EmbeddedTestServer* cors_embedded_test_server() const { |
| 115 return cors_embedded_test_server_.get(); | 102 return cors_embedded_test_server_.get(); |
| 116 } | 103 } |
| 117 | 104 |
| 118 private: | 105 private: |
| 119 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 106 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 120 std::unique_ptr<MockWebContentsDelegate> mock_web_contents_delegate_; | 107 std::unique_ptr<MockWebContentsDelegate> mock_web_contents_delegate_; |
| 121 std::unique_ptr<net::EmbeddedTestServer> cors_embedded_test_server_; | 108 std::unique_ptr<net::EmbeddedTestServer> cors_embedded_test_server_; |
| 109 GURL manifest_url_; |
| 122 Manifest manifest_; | 110 Manifest manifest_; |
| 123 int console_error_count_; | 111 int console_error_count_; |
| 124 bool has_manifest_; | |
| 125 | 112 |
| 126 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); | 113 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); |
| 127 }; | 114 }; |
| 128 | 115 |
| 129 // The implementation of AddMessageToConsole isn't inlined because it needs | 116 // The implementation of AddMessageToConsole isn't inlined because it needs |
| 130 // to know about |test_|. | 117 // to know about |test_|. |
| 131 bool MockWebContentsDelegate::AddMessageToConsole( | 118 bool MockWebContentsDelegate::AddMessageToConsole( |
| 132 WebContents* source, | 119 WebContents* source, |
| 133 int32_t level, | 120 int32_t level, |
| 134 const base::string16& message, | 121 const base::string16& message, |
| 135 int32_t line_no, | 122 int32_t line_no, |
| 136 const base::string16& source_id) { | 123 const base::string16& source_id) { |
| 137 DCHECK(source == web_contents_); | 124 DCHECK(source == web_contents_); |
| 138 | 125 |
| 139 if (level == logging::LOG_ERROR || level == logging::LOG_WARNING) | 126 if (level == logging::LOG_ERROR || level == logging::LOG_WARNING) |
| 140 test_->OnReceivedConsoleError(); | 127 test_->OnReceivedConsoleError(); |
| 141 return false; | 128 return false; |
| 142 } | 129 } |
| 143 | 130 |
| 144 // If a page has no manifest, requesting a manifest should return the empty | 131 // If a page has no manifest, requesting a manifest should return the empty |
| 145 // manifest. | 132 // manifest. The URL should be empty. |
| 146 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoManifest) { | 133 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoManifest) { |
| 147 GURL test_url = GetTestUrl("manifest", "no-manifest.html"); | 134 GURL test_url = GetTestUrl("manifest", "no-manifest.html"); |
| 148 | 135 |
| 149 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 136 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 150 shell()->LoadURL(test_url); | 137 shell()->LoadURL(test_url); |
| 151 navigation_observer.Wait(); | 138 navigation_observer.Wait(); |
| 152 | 139 |
| 153 GetManifestAndWait(); | 140 GetManifestAndWait(); |
| 154 EXPECT_TRUE(manifest().IsEmpty()); | 141 EXPECT_TRUE(manifest().IsEmpty()); |
| 155 | 142 EXPECT_TRUE(manifest_url().is_empty()); |
| 156 HasManifestAndWait(); | |
| 157 EXPECT_FALSE(has_manifest()); | |
| 158 EXPECT_EQ(0u, console_error_count()); | 143 EXPECT_EQ(0u, console_error_count()); |
| 159 } | 144 } |
| 160 | 145 |
| 161 // If a page manifest points to a 404 URL, requesting the manifest should return | 146 // If a page manifest points to a 404 URL, requesting the manifest should return |
| 162 // the empty manifest. However, HasManifest will return true. | 147 // the empty manifest. However, the manifest URL will be non-empty. |
| 163 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, 404Manifest) { | 148 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, 404Manifest) { |
| 164 GURL test_url = GetTestUrl("manifest", "404-manifest.html"); | 149 GURL test_url = GetTestUrl("manifest", "404-manifest.html"); |
| 165 | 150 |
| 166 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 151 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 167 shell()->LoadURL(test_url); | 152 shell()->LoadURL(test_url); |
| 168 navigation_observer.Wait(); | 153 navigation_observer.Wait(); |
| 169 | 154 |
| 170 GetManifestAndWait(); | 155 GetManifestAndWait(); |
| 171 EXPECT_TRUE(manifest().IsEmpty()); | 156 EXPECT_TRUE(manifest().IsEmpty()); |
| 172 | 157 EXPECT_FALSE(manifest_url().is_empty()); |
| 173 HasManifestAndWait(); | |
| 174 EXPECT_TRUE(has_manifest()); | |
| 175 EXPECT_EQ(0u, console_error_count()); | 158 EXPECT_EQ(0u, console_error_count()); |
| 176 } | 159 } |
| 177 | 160 |
| 178 // If a page has an empty manifest, requesting the manifest should return the | 161 // If a page has an empty manifest, requesting the manifest should return the |
| 179 // empty manifest. | 162 // empty manifest. The manifest URL should be non-empty. |
| 180 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, EmptyManifest) { | 163 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, EmptyManifest) { |
| 181 GURL test_url = GetTestUrl("manifest", "empty-manifest.html"); | 164 GURL test_url = GetTestUrl("manifest", "empty-manifest.html"); |
| 182 | 165 |
| 183 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 166 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 184 shell()->LoadURL(test_url); | 167 shell()->LoadURL(test_url); |
| 185 navigation_observer.Wait(); | 168 navigation_observer.Wait(); |
| 186 | 169 |
| 187 GetManifestAndWait(); | 170 GetManifestAndWait(); |
| 188 EXPECT_TRUE(manifest().IsEmpty()); | 171 EXPECT_TRUE(manifest().IsEmpty()); |
| 189 | 172 EXPECT_FALSE(manifest_url().is_empty()); |
| 190 HasManifestAndWait(); | |
| 191 EXPECT_TRUE(has_manifest()); | |
| 192 EXPECT_EQ(0u, console_error_count()); | 173 EXPECT_EQ(0u, console_error_count()); |
| 193 } | 174 } |
| 194 | 175 |
| 195 // If a page's manifest can't be parsed correctly, requesting the manifest | 176 // If a page's manifest can't be parsed correctly, requesting the manifest |
| 196 // should return an empty manifest. | 177 // should return an empty manifest. The manifest URL should be non-empty. |
| 197 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParseErrorManifest) { | 178 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParseErrorManifest) { |
| 198 GURL test_url = GetTestUrl("manifest", "parse-error-manifest.html"); | 179 GURL test_url = GetTestUrl("manifest", "parse-error-manifest.html"); |
| 199 | 180 |
| 200 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 181 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 201 shell()->LoadURL(test_url); | 182 shell()->LoadURL(test_url); |
| 202 navigation_observer.Wait(); | 183 navigation_observer.Wait(); |
| 203 | 184 |
| 204 GetManifestAndWait(); | 185 GetManifestAndWait(); |
| 205 EXPECT_TRUE(manifest().IsEmpty()); | 186 EXPECT_TRUE(manifest().IsEmpty()); |
| 206 | 187 EXPECT_FALSE(manifest_url().is_empty()); |
| 207 HasManifestAndWait(); | |
| 208 EXPECT_TRUE(has_manifest()); | |
| 209 EXPECT_EQ(1u, console_error_count()); | 188 EXPECT_EQ(1u, console_error_count()); |
| 210 } | 189 } |
| 211 | 190 |
| 212 // If a page has a manifest that can be fetched and parsed, requesting the | 191 // If a page has a manifest that can be fetched and parsed, requesting the |
| 213 // manifest should return a properly filled manifest. | 192 // manifest should return a properly filled manifest. The manifest URL should be |
| 193 // non-empty. |
| 214 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DummyManifest) { | 194 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DummyManifest) { |
| 215 GURL test_url = GetTestUrl("manifest", "dummy-manifest.html"); | 195 GURL test_url = GetTestUrl("manifest", "dummy-manifest.html"); |
| 216 | 196 |
| 217 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 197 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 218 shell()->LoadURL(test_url); | 198 shell()->LoadURL(test_url); |
| 219 navigation_observer.Wait(); | 199 navigation_observer.Wait(); |
| 220 | 200 |
| 221 GetManifestAndWait(); | 201 GetManifestAndWait(); |
| 222 EXPECT_FALSE(manifest().IsEmpty()); | 202 EXPECT_FALSE(manifest().IsEmpty()); |
| 203 EXPECT_FALSE(manifest_url().is_empty()); |
| 223 | 204 |
| 224 HasManifestAndWait(); | |
| 225 EXPECT_TRUE(has_manifest()); | |
| 226 EXPECT_EQ(0u, console_error_count()); | 205 EXPECT_EQ(0u, console_error_count()); |
| 227 } | 206 } |
| 228 | 207 |
| 229 // If a page changes manifest during its life-time, requesting the manifest | 208 // If a page changes manifest during its life-time, requesting the manifest |
| 230 // should return the current manifest. | 209 // should return the current manifest. |
| 231 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DynamicManifest) { | 210 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DynamicManifest) { |
| 232 GURL test_url = GetTestUrl("manifest", "dynamic-manifest.html"); | 211 GURL test_url = GetTestUrl("manifest", "dynamic-manifest.html"); |
| 233 | 212 |
| 234 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 213 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 235 shell()->LoadURL(test_url); | 214 shell()->LoadURL(test_url); |
| 236 navigation_observer.Wait(); | 215 navigation_observer.Wait(); |
| 237 | 216 |
| 238 { | 217 { |
| 239 GetManifestAndWait(); | 218 GetManifestAndWait(); |
| 240 EXPECT_TRUE(manifest().IsEmpty()); | 219 EXPECT_TRUE(manifest().IsEmpty()); |
| 241 | 220 EXPECT_TRUE(manifest_url().is_empty()); |
| 242 HasManifestAndWait(); | |
| 243 EXPECT_FALSE(has_manifest()); | |
| 244 } | 221 } |
| 245 | 222 |
| 246 { | 223 { |
| 247 std::string manifest_url = | 224 std::string manifest_link = |
| 248 GetTestUrl("manifest", "dummy-manifest.json").spec(); | 225 GetTestUrl("manifest", "dummy-manifest.json").spec(); |
| 249 ASSERT_TRUE(content::ExecuteScript( | 226 ASSERT_TRUE(content::ExecuteScript( |
| 250 shell(), "setManifestTo('" + manifest_url + "')")); | 227 shell(), "setManifestTo('" + manifest_link + "')")); |
| 251 | 228 |
| 252 GetManifestAndWait(); | 229 GetManifestAndWait(); |
| 253 EXPECT_FALSE(manifest().IsEmpty()); | 230 EXPECT_FALSE(manifest().IsEmpty()); |
| 254 | 231 EXPECT_FALSE(manifest_url().is_empty()); |
| 255 HasManifestAndWait(); | |
| 256 EXPECT_TRUE(has_manifest()); | |
| 257 } | 232 } |
| 258 | 233 |
| 259 { | 234 { |
| 260 std::string manifest_url = | 235 std::string manifest_link = |
| 261 GetTestUrl("manifest", "empty-manifest.json").spec(); | 236 GetTestUrl("manifest", "empty-manifest.json").spec(); |
| 262 ASSERT_TRUE(content::ExecuteScript( | 237 ASSERT_TRUE(content::ExecuteScript( |
| 263 shell(), "setManifestTo('" + manifest_url + "')")); | 238 shell(), "setManifestTo('" + manifest_link + "')")); |
| 264 | 239 |
| 265 GetManifestAndWait(); | 240 GetManifestAndWait(); |
| 266 EXPECT_TRUE(manifest().IsEmpty()); | 241 EXPECT_TRUE(manifest().IsEmpty()); |
| 267 | 242 EXPECT_FALSE(manifest_url().is_empty()); |
| 268 HasManifestAndWait(); | |
| 269 EXPECT_TRUE(has_manifest()); | |
| 270 } | 243 } |
| 271 | 244 |
| 272 EXPECT_EQ(0u, console_error_count()); | 245 EXPECT_EQ(0u, console_error_count()); |
| 273 } | 246 } |
| 274 | 247 |
| 275 // If a page's manifest lives in a different origin, it should follow the CORS | 248 // If a page's manifest lives in a different origin, it should follow the CORS |
| 276 // rules and requesting the manifest should return an empty manifest (unless the | 249 // rules and requesting the manifest should return an empty manifest (unless the |
| 277 // response contains CORS headers). | 250 // response contains CORS headers). |
| 278 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { | 251 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { |
| 279 ASSERT_TRUE(embedded_test_server()->Start()); | 252 ASSERT_TRUE(embedded_test_server()->Start()); |
| 280 ASSERT_TRUE(cors_embedded_test_server()->Start()); | 253 ASSERT_TRUE(cors_embedded_test_server()->Start()); |
| 281 ASSERT_NE(embedded_test_server()->port(), | 254 ASSERT_NE(embedded_test_server()->port(), |
| 282 cors_embedded_test_server()->port()); | 255 cors_embedded_test_server()->port()); |
| 283 | 256 |
| 284 GURL test_url = | 257 GURL test_url = |
| 285 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); | 258 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); |
| 286 | 259 |
| 287 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 260 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 288 shell()->LoadURL(test_url); | 261 shell()->LoadURL(test_url); |
| 289 navigation_observer.Wait(); | 262 navigation_observer.Wait(); |
| 290 | 263 |
| 291 std::string manifest_url = cors_embedded_test_server()->GetURL( | 264 std::string manifest_link = cors_embedded_test_server()->GetURL( |
| 292 "/manifest/dummy-manifest.json").spec(); | 265 "/manifest/dummy-manifest.json").spec(); |
| 293 ASSERT_TRUE( | 266 ASSERT_TRUE(content::ExecuteScript(shell(), |
| 294 content::ExecuteScript(shell(), "setManifestTo('" + manifest_url + "')")); | 267 "setManifestTo('" + manifest_link + "')")); |
| 295 | 268 |
| 296 GetManifestAndWait(); | 269 GetManifestAndWait(); |
| 297 EXPECT_TRUE(manifest().IsEmpty()); | 270 EXPECT_TRUE(manifest().IsEmpty()); |
| 298 | 271 EXPECT_FALSE(manifest_url().is_empty()); |
| 299 HasManifestAndWait(); | |
| 300 EXPECT_TRUE(has_manifest()); | |
| 301 EXPECT_EQ(0u, console_error_count()); | 272 EXPECT_EQ(0u, console_error_count()); |
| 302 | 273 |
| 303 // The purpose of this second load is to make sure the first load is fully | 274 // The purpose of this second load is to make sure the first load is fully |
| 304 // finished. The first load will fail because of Access Control error but the | 275 // finished. The first load will fail because of Access Control error but the |
| 305 // underlying Blink loader will continue fetching the file. There is no | 276 // underlying Blink loader will continue fetching the file. There is no |
| 306 // reliable way to know when the fetch is finished from the browser test | 277 // reliable way to know when the fetch is finished from the browser test |
| 307 // except by fetching the same file from same origin, making it succeed when | 278 // except by fetching the same file from same origin, making it succeed when |
| 308 // it is actually fully loaded. | 279 // it is actually fully loaded. |
| 309 manifest_url = | 280 manifest_link = |
| 310 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec(); | 281 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec(); |
| 311 ASSERT_TRUE( | 282 ASSERT_TRUE(content::ExecuteScript(shell(), |
| 312 content::ExecuteScript(shell(), "setManifestTo('" + manifest_url + "')")); | 283 "setManifestTo('" + manifest_link + "')")); |
| 313 GetManifestAndWait(); | 284 GetManifestAndWait(); |
| 314 } | 285 } |
| 315 | 286 |
| 316 // If a page's manifest lives in a different origin, it should be accessible if | 287 // If a page's manifest lives in a different origin, it should be accessible if |
| 317 // it has valid access controls headers. | 288 // it has valid access controls headers. |
| 318 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifestWithAcessControls) { | 289 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifestWithAcessControls) { |
| 319 ASSERT_TRUE(embedded_test_server()->Start()); | 290 ASSERT_TRUE(embedded_test_server()->Start()); |
| 320 ASSERT_TRUE(cors_embedded_test_server()->Start()); | 291 ASSERT_TRUE(cors_embedded_test_server()->Start()); |
| 321 ASSERT_NE(embedded_test_server()->port(), | 292 ASSERT_NE(embedded_test_server()->port(), |
| 322 cors_embedded_test_server()->port()); | 293 cors_embedded_test_server()->port()); |
| 323 | 294 |
| 324 GURL test_url = | 295 GURL test_url = |
| 325 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); | 296 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); |
| 326 | 297 |
| 327 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 298 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 328 shell()->LoadURL(test_url); | 299 shell()->LoadURL(test_url); |
| 329 navigation_observer.Wait(); | 300 navigation_observer.Wait(); |
| 330 | 301 |
| 331 std::string manifest_url = cors_embedded_test_server()->GetURL( | 302 std::string manifest_link = cors_embedded_test_server()->GetURL( |
| 332 "/manifest/manifest-cors.json").spec(); | 303 "/manifest/manifest-cors.json").spec(); |
| 333 ASSERT_TRUE( | 304 ASSERT_TRUE(content::ExecuteScript(shell(), |
| 334 content::ExecuteScript(shell(), "setManifestTo('" + manifest_url + "')")); | 305 "setManifestTo('" + manifest_link + "')")); |
| 335 | 306 |
| 336 GetManifestAndWait(); | 307 GetManifestAndWait(); |
| 337 EXPECT_FALSE(manifest().IsEmpty()); | 308 EXPECT_FALSE(manifest().IsEmpty()); |
| 338 | 309 EXPECT_FALSE(manifest_url().is_empty()); |
| 339 HasManifestAndWait(); | |
| 340 EXPECT_TRUE(has_manifest()); | |
| 341 EXPECT_EQ(0u, console_error_count()); | 310 EXPECT_EQ(0u, console_error_count()); |
| 342 } | 311 } |
| 343 | 312 |
| 344 // If a page's manifest is in an insecure origin while the page is in a secure | 313 // If a page's manifest is in an insecure origin while the page is in a secure |
| 345 // origin, requesting the manifest should return the empty manifest. | 314 // origin, requesting the manifest should return the empty manifest. |
| 346 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { | 315 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { |
| 347 std::unique_ptr<net::EmbeddedTestServer> https_server( | 316 std::unique_ptr<net::EmbeddedTestServer> https_server( |
| 348 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 317 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 349 https_server->ServeFilesFromSourceDirectory("content/test/data"); | 318 https_server->ServeFilesFromSourceDirectory("content/test/data"); |
| 350 | 319 |
| 351 ASSERT_TRUE(embedded_test_server()->Start()); | 320 ASSERT_TRUE(embedded_test_server()->Start()); |
| 352 ASSERT_TRUE(https_server->Start()); | 321 ASSERT_TRUE(https_server->Start()); |
| 353 | 322 |
| 354 GURL test_url = | 323 GURL test_url = |
| 355 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); | 324 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); |
| 356 | 325 |
| 357 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 326 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 358 shell()->LoadURL(test_url); | 327 shell()->LoadURL(test_url); |
| 359 navigation_observer.Wait(); | 328 navigation_observer.Wait(); |
| 360 | 329 |
| 361 std::string manifest_url = | 330 std::string manifest_link = |
| 362 https_server->GetURL("/manifest/dummy-manifest.json").spec(); | 331 https_server->GetURL("/manifest/dummy-manifest.json").spec(); |
| 363 ASSERT_TRUE( | 332 ASSERT_TRUE(content::ExecuteScript(shell(), |
| 364 content::ExecuteScript(shell(), "setManifestTo('" + manifest_url + "')")); | 333 "setManifestTo('" + manifest_link + "')")); |
| 365 | 334 |
| 366 GetManifestAndWait(); | 335 GetManifestAndWait(); |
| 367 EXPECT_TRUE(manifest().IsEmpty()); | 336 EXPECT_TRUE(manifest().IsEmpty()); |
| 368 | 337 EXPECT_FALSE(manifest_url().is_empty()); |
| 369 HasManifestAndWait(); | |
| 370 EXPECT_TRUE(has_manifest()); | |
| 371 EXPECT_EQ(0u, console_error_count()); | 338 EXPECT_EQ(0u, console_error_count()); |
| 372 } | 339 } |
| 373 | 340 |
| 374 // If a page's manifest has some parsing errors, they should show up in the | 341 // If a page's manifest has some parsing errors, they should show up in the |
| 375 // developer console. | 342 // developer console. |
| 376 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParsingErrorsManifest) { | 343 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParsingErrorsManifest) { |
| 377 GURL test_url = GetTestUrl("manifest", "parsing-errors.html"); | 344 GURL test_url = GetTestUrl("manifest", "parsing-errors.html"); |
| 378 | 345 |
| 379 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 346 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 380 shell()->LoadURL(test_url); | 347 shell()->LoadURL(test_url); |
| 381 navigation_observer.Wait(); | 348 navigation_observer.Wait(); |
| 382 | 349 |
| 383 GetManifestAndWait(); | 350 GetManifestAndWait(); |
| 384 EXPECT_TRUE(manifest().IsEmpty()); | 351 EXPECT_TRUE(manifest().IsEmpty()); |
| 352 EXPECT_FALSE(manifest_url().is_empty()); |
| 385 EXPECT_EQ(6u, console_error_count()); | 353 EXPECT_EQ(6u, console_error_count()); |
| 386 | |
| 387 HasManifestAndWait(); | |
| 388 EXPECT_TRUE(has_manifest()); | |
| 389 } | 354 } |
| 390 | 355 |
| 391 // If a page has a manifest and the page is navigated to a page without a | 356 // If a page has a manifest and the page is navigated to a page without a |
| 392 // manifest, the page's manifest should be updated. | 357 // manifest, the page's manifest should be updated. |
| 393 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, Navigation) { | 358 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, Navigation) { |
| 394 ASSERT_TRUE(embedded_test_server()->Start()); | 359 ASSERT_TRUE(embedded_test_server()->Start()); |
| 395 { | 360 { |
| 396 GURL test_url = | 361 GURL test_url = |
| 397 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); | 362 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); |
| 398 | 363 |
| 399 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 364 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 400 shell()->LoadURL(test_url); | 365 shell()->LoadURL(test_url); |
| 401 navigation_observer.Wait(); | 366 navigation_observer.Wait(); |
| 402 | 367 |
| 403 GetManifestAndWait(); | 368 GetManifestAndWait(); |
| 404 EXPECT_FALSE(manifest().IsEmpty()); | 369 EXPECT_FALSE(manifest().IsEmpty()); |
| 405 | 370 EXPECT_FALSE(manifest_url().is_empty()); |
| 406 HasManifestAndWait(); | |
| 407 EXPECT_TRUE(has_manifest()); | |
| 408 EXPECT_EQ(0u, console_error_count()); | 371 EXPECT_EQ(0u, console_error_count()); |
| 409 } | 372 } |
| 410 | 373 |
| 411 { | 374 { |
| 412 GURL test_url = | 375 GURL test_url = |
| 413 embedded_test_server()->GetURL("/manifest/no-manifest.html"); | 376 embedded_test_server()->GetURL("/manifest/no-manifest.html"); |
| 414 | 377 |
| 415 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 378 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 416 shell()->LoadURL(test_url); | 379 shell()->LoadURL(test_url); |
| 417 navigation_observer.Wait(); | 380 navigation_observer.Wait(); |
| 418 | 381 |
| 419 GetManifestAndWait(); | 382 GetManifestAndWait(); |
| 420 EXPECT_TRUE(manifest().IsEmpty()); | 383 EXPECT_TRUE(manifest().IsEmpty()); |
| 421 EXPECT_EQ(0u, console_error_count()); | 384 EXPECT_EQ(0u, console_error_count()); |
| 422 | 385 EXPECT_TRUE(manifest_url().is_empty()); |
| 423 HasManifestAndWait(); | |
| 424 EXPECT_FALSE(has_manifest()); | |
| 425 } | 386 } |
| 426 } | 387 } |
| 427 | 388 |
| 428 // If a page has a manifest and the page is navigated using pushState (ie. same | 389 // If a page has a manifest and the page is navigated using pushState (ie. same |
| 429 // page), it should keep its manifest state. | 390 // page), it should keep its manifest state. |
| 430 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, PushStateNavigation) { | 391 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, PushStateNavigation) { |
| 431 ASSERT_TRUE(embedded_test_server()->Start()); | 392 ASSERT_TRUE(embedded_test_server()->Start()); |
| 432 GURL test_url = | 393 GURL test_url = |
| 433 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); | 394 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); |
| 434 | 395 |
| 435 { | 396 { |
| 436 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 397 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 437 shell()->LoadURL(test_url); | 398 shell()->LoadURL(test_url); |
| 438 navigation_observer.Wait(); | 399 navigation_observer.Wait(); |
| 439 } | 400 } |
| 440 | 401 |
| 441 { | 402 { |
| 442 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 403 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 443 ASSERT_TRUE(content::ExecuteScript( | 404 ASSERT_TRUE(content::ExecuteScript( |
| 444 shell(), "history.pushState({foo: \"bar\"}, 'page', 'page.html');")); | 405 shell(), "history.pushState({foo: \"bar\"}, 'page', 'page.html');")); |
| 445 navigation_observer.Wait(); | 406 navigation_observer.Wait(); |
| 446 } | 407 } |
| 447 | 408 |
| 448 GetManifestAndWait(); | 409 GetManifestAndWait(); |
| 449 EXPECT_FALSE(manifest().IsEmpty()); | 410 EXPECT_FALSE(manifest().IsEmpty()); |
| 450 | 411 EXPECT_FALSE(manifest_url().is_empty()); |
| 451 HasManifestAndWait(); | |
| 452 EXPECT_TRUE(has_manifest()); | |
| 453 EXPECT_EQ(0u, console_error_count()); | 412 EXPECT_EQ(0u, console_error_count()); |
| 454 } | 413 } |
| 455 | 414 |
| 456 // If a page has a manifest and is navigated using an anchor (ie. same page), it | 415 // If a page has a manifest and is navigated using an anchor (ie. same page), it |
| 457 // should keep its manifest state. | 416 // should keep its manifest state. |
| 458 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, AnchorNavigation) { | 417 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, AnchorNavigation) { |
| 459 ASSERT_TRUE(embedded_test_server()->Start()); | 418 ASSERT_TRUE(embedded_test_server()->Start()); |
| 460 GURL test_url = | 419 GURL test_url = |
| 461 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); | 420 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); |
| 462 | 421 |
| 463 { | 422 { |
| 464 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 423 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 465 shell()->LoadURL(test_url); | 424 shell()->LoadURL(test_url); |
| 466 navigation_observer.Wait(); | 425 navigation_observer.Wait(); |
| 467 } | 426 } |
| 468 | 427 |
| 469 { | 428 { |
| 470 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 429 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 471 ASSERT_TRUE(content::ExecuteScript( | 430 ASSERT_TRUE(content::ExecuteScript( |
| 472 shell(), | 431 shell(), |
| 473 "var a = document.createElement('a'); a.href='#foo';" | 432 "var a = document.createElement('a'); a.href='#foo';" |
| 474 "document.body.appendChild(a); a.click();")); | 433 "document.body.appendChild(a); a.click();")); |
| 475 navigation_observer.Wait(); | 434 navigation_observer.Wait(); |
| 476 } | 435 } |
| 477 | 436 |
| 478 GetManifestAndWait(); | 437 GetManifestAndWait(); |
| 479 EXPECT_FALSE(manifest().IsEmpty()); | 438 EXPECT_FALSE(manifest().IsEmpty()); |
| 480 EXPECT_EQ(0u, console_error_count()); | 439 EXPECT_FALSE(manifest_url().is_empty()); |
| 481 | |
| 482 HasManifestAndWait(); | |
| 483 EXPECT_TRUE(has_manifest()); | |
| 484 EXPECT_EQ(0u, console_error_count()); | 440 EXPECT_EQ(0u, console_error_count()); |
| 485 } | 441 } |
| 486 | 442 |
| 487 namespace { | 443 namespace { |
| 488 | 444 |
| 489 std::unique_ptr<net::test_server::HttpResponse> CustomHandleRequestForCookies( | 445 std::unique_ptr<net::test_server::HttpResponse> CustomHandleRequestForCookies( |
| 490 const net::test_server::HttpRequest& request) { | 446 const net::test_server::HttpRequest& request) { |
| 491 if (request.relative_url == "/index.html") { | 447 if (request.relative_url == "/index.html") { |
| 492 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( | 448 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 493 new net::test_server::BasicHttpResponse()); | 449 new net::test_server::BasicHttpResponse()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), | 485 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), |
| 530 custom_embedded_test_server->base_url(), | 486 custom_embedded_test_server->base_url(), |
| 531 "foobar")); | 487 "foobar")); |
| 532 | 488 |
| 533 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 489 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 534 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); | 490 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); |
| 535 navigation_observer.Wait(); | 491 navigation_observer.Wait(); |
| 536 | 492 |
| 537 GetManifestAndWait(); | 493 GetManifestAndWait(); |
| 538 EXPECT_FALSE(manifest().IsEmpty()); | 494 EXPECT_FALSE(manifest().IsEmpty()); |
| 539 | 495 EXPECT_FALSE(manifest_url().is_empty()); |
| 540 HasManifestAndWait(); | |
| 541 EXPECT_TRUE(has_manifest()); | |
| 542 EXPECT_EQ(0u, console_error_count()); | 496 EXPECT_EQ(0u, console_error_count()); |
| 543 | 497 |
| 544 // The custom embedded test server will fill the name field with the cookie | 498 // The custom embedded test server will fill the name field with the cookie |
| 545 // content. | 499 // content. |
| 546 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "foobar")); | 500 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "foobar")); |
| 547 } | 501 } |
| 548 | 502 |
| 549 namespace { | 503 namespace { |
| 550 | 504 |
| 551 std::unique_ptr<net::test_server::HttpResponse> CustomHandleRequestForNoCookies( | 505 std::unique_ptr<net::test_server::HttpResponse> CustomHandleRequestForNoCookies( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), | 542 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), |
| 589 custom_embedded_test_server->base_url(), | 543 custom_embedded_test_server->base_url(), |
| 590 "foobar")); | 544 "foobar")); |
| 591 | 545 |
| 592 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 546 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 593 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); | 547 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); |
| 594 navigation_observer.Wait(); | 548 navigation_observer.Wait(); |
| 595 | 549 |
| 596 GetManifestAndWait(); | 550 GetManifestAndWait(); |
| 597 EXPECT_FALSE(manifest().IsEmpty()); | 551 EXPECT_FALSE(manifest().IsEmpty()); |
| 598 | 552 EXPECT_FALSE(manifest_url().is_empty()); |
| 599 HasManifestAndWait(); | |
| 600 EXPECT_TRUE(has_manifest()); | |
| 601 EXPECT_EQ(0u, console_error_count()); | 553 EXPECT_EQ(0u, console_error_count()); |
| 602 | 554 |
| 603 // The custom embedded test server will fill set the name to 'no cookies' if | 555 // The custom embedded test server will fill set the name to 'no cookies' if |
| 604 // it did not find cookies. | 556 // it did not find cookies. |
| 605 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); | 557 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); |
| 606 } | 558 } |
| 607 | 559 |
| 608 } // namespace content | 560 } // namespace content |
| OLD | NEW |