Chromium Code Reviews| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "content/public/browser/web_contents.h" | 6 #include "content/public/browser/web_contents.h" |
| 7 #include "content/public/common/content_switches.h" | 7 #include "content/public/common/content_switches.h" |
| 8 #include "content/public/common/manifest.h" | 8 #include "content/public/common/manifest.h" |
| 9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
| 11 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
| 12 #include "content/public/test/test_navigation_observer.h" | 12 #include "content/public/test/test_navigation_observer.h" |
| 13 #include "content/shell/browser/shell.h" | 13 #include "content/shell/browser/shell.h" |
| 14 #include "net/test/embedded_test_server/embedded_test_server.h" | 14 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 class ManifestBrowserTest : public ContentBrowserTest { | 18 class ManifestBrowserTest : public ContentBrowserTest { |
| 19 protected: | 19 protected: |
| 20 ManifestBrowserTest() {} | 20 ManifestBrowserTest() { |
| 21 ~ManifestBrowserTest() override {} | 21 console_errors_count_ = 0; |
| 22 logging::SetLogMessageHandler(&ManifestBrowserTest::CatchConsoleErrors); | |
| 23 } | |
| 24 | |
| 25 ~ManifestBrowserTest() override { | |
| 26 logging::SetLogMessageHandler(nullptr); | |
|
Peter Beverloo
2014/11/27 13:24:31
indentation.
mlamouri (slow - plz ping)
2014/11/27 13:49:08
Done.
| |
| 27 } | |
| 22 | 28 |
| 23 void GetManifestAndWait() { | 29 void GetManifestAndWait() { |
| 24 shell()->web_contents()->GetManifest( | 30 shell()->web_contents()->GetManifest( |
| 25 base::Bind(&ManifestBrowserTest::OnGetManifest, | 31 base::Bind(&ManifestBrowserTest::OnGetManifest, |
| 26 base::Unretained(this))); | 32 base::Unretained(this))); |
| 27 | 33 |
| 28 message_loop_runner_ = new MessageLoopRunner(); | 34 message_loop_runner_ = new MessageLoopRunner(); |
| 29 message_loop_runner_->Run(); | 35 message_loop_runner_->Run(); |
| 30 } | 36 } |
| 31 | 37 |
| 32 void OnGetManifest(const Manifest& manifest) { | 38 void OnGetManifest(const Manifest& manifest) { |
| 33 manifest_ = manifest; | 39 manifest_ = manifest; |
| 34 message_loop_runner_->Quit(); | 40 message_loop_runner_->Quit(); |
| 35 } | 41 } |
| 36 | 42 |
| 37 const Manifest& manifest() const { | 43 const Manifest& manifest() const { |
| 38 return manifest_; | 44 return manifest_; |
| 39 } | 45 } |
| 40 | 46 |
| 47 static bool CatchConsoleErrors(int severity, | |
| 48 const char* file, | |
| 49 int line, | |
| 50 size_t message_start, | |
| 51 const std::string& str) { | |
| 52 if (severity == logging::LOG_INFO && | |
| 53 file && file == std::string("CONSOLE")) { | |
|
Peter Beverloo
2014/11/27 13:24:31
Mm. This feels rather fragile. Have you considered
mlamouri (slow - plz ping)
2014/11/27 13:49:08
Do you have examples?
Peter Beverloo
2014/11/27 13:55:15
Not of this specific scenario. The tests using a s
| |
| 54 console_errors_count_++; | |
| 55 } | |
| 56 | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 static int console_errors_count_; | |
| 61 | |
| 41 private: | 62 private: |
| 42 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 63 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 43 Manifest manifest_; | 64 Manifest manifest_; |
| 44 | 65 |
| 45 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); | 66 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); |
| 46 }; | 67 }; |
| 47 | 68 |
| 69 int ManifestBrowserTest::console_errors_count_ = 0; | |
| 70 | |
| 48 // If a page has no manifest, requesting a manifest should return the empty | 71 // If a page has no manifest, requesting a manifest should return the empty |
| 49 // manifest. | 72 // manifest. |
| 50 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoManifest) { | 73 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoManifest) { |
| 51 GURL test_url = GetTestUrl("manifest", "no-manifest.html"); | 74 GURL test_url = GetTestUrl("manifest", "no-manifest.html"); |
| 52 | 75 |
| 53 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 76 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 54 shell()->LoadURL(test_url); | 77 shell()->LoadURL(test_url); |
| 55 navigation_observer.Wait(); | 78 navigation_observer.Wait(); |
| 56 | 79 |
| 57 GetManifestAndWait(); | 80 GetManifestAndWait(); |
| 58 EXPECT_TRUE(manifest().IsEmpty()); | 81 EXPECT_TRUE(manifest().IsEmpty()); |
| 82 EXPECT_EQ(0, ManifestBrowserTest::console_errors_count_); | |
| 59 } | 83 } |
| 60 | 84 |
| 61 // If a page manifest points to a 404 URL, requesting the manifest should return | 85 // If a page manifest points to a 404 URL, requesting the manifest should return |
| 62 // the empty manifest. | 86 // the empty manifest. |
| 63 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, 404Manifest) { | 87 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, 404Manifest) { |
| 64 GURL test_url = GetTestUrl("manifest", "404-manifest.html"); | 88 GURL test_url = GetTestUrl("manifest", "404-manifest.html"); |
| 65 | 89 |
| 66 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 90 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 67 shell()->LoadURL(test_url); | 91 shell()->LoadURL(test_url); |
| 68 navigation_observer.Wait(); | 92 navigation_observer.Wait(); |
| 69 | 93 |
| 70 GetManifestAndWait(); | 94 GetManifestAndWait(); |
| 71 EXPECT_TRUE(manifest().IsEmpty()); | 95 EXPECT_TRUE(manifest().IsEmpty()); |
| 96 EXPECT_EQ(0, ManifestBrowserTest::console_errors_count_); | |
| 72 } | 97 } |
| 73 | 98 |
| 74 // If a page has an empty manifest, requesting the manifest should return the | 99 // If a page has an empty manifest, requesting the manifest should return the |
| 75 // empty manifest. | 100 // empty manifest. |
| 76 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, EmptyManifest) { | 101 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, EmptyManifest) { |
| 77 GURL test_url = GetTestUrl("manifest", "empty-manifest.html"); | 102 GURL test_url = GetTestUrl("manifest", "empty-manifest.html"); |
| 78 | 103 |
| 79 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 104 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 80 shell()->LoadURL(test_url); | 105 shell()->LoadURL(test_url); |
| 81 navigation_observer.Wait(); | 106 navigation_observer.Wait(); |
| 82 | 107 |
| 83 GetManifestAndWait(); | 108 GetManifestAndWait(); |
| 84 EXPECT_TRUE(manifest().IsEmpty()); | 109 EXPECT_TRUE(manifest().IsEmpty()); |
| 110 EXPECT_EQ(0, ManifestBrowserTest::console_errors_count_); | |
| 85 } | 111 } |
| 86 | 112 |
| 87 // If a page's manifest can't be parsed correctly, requesting the manifest | 113 // If a page's manifest can't be parsed correctly, requesting the manifest |
| 88 // should return an empty manifest. | 114 // should return an empty manifest. |
| 89 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParseErrorManifest) { | 115 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParseErrorManifest) { |
| 90 GURL test_url = GetTestUrl("manifest", "parse-error-manifest.html"); | 116 GURL test_url = GetTestUrl("manifest", "parse-error-manifest.html"); |
| 91 | 117 |
| 92 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 118 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 93 shell()->LoadURL(test_url); | 119 shell()->LoadURL(test_url); |
| 94 navigation_observer.Wait(); | 120 navigation_observer.Wait(); |
| 95 | 121 |
| 96 GetManifestAndWait(); | 122 GetManifestAndWait(); |
| 97 EXPECT_TRUE(manifest().IsEmpty()); | 123 EXPECT_TRUE(manifest().IsEmpty()); |
| 124 EXPECT_EQ(1, ManifestBrowserTest::console_errors_count_); | |
| 98 } | 125 } |
| 99 | 126 |
| 100 // If a page has a manifest that can be fetched and parsed, requesting the | 127 // If a page has a manifest that can be fetched and parsed, requesting the |
| 101 // manifest should return a properly filled manifest. | 128 // manifest should return a properly filled manifest. |
| 102 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DummyManifest) { | 129 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DummyManifest) { |
| 103 GURL test_url = GetTestUrl("manifest", "dummy-manifest.html"); | 130 GURL test_url = GetTestUrl("manifest", "dummy-manifest.html"); |
| 104 | 131 |
| 105 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 132 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 106 shell()->LoadURL(test_url); | 133 shell()->LoadURL(test_url); |
| 107 navigation_observer.Wait(); | 134 navigation_observer.Wait(); |
| 108 | 135 |
| 109 GetManifestAndWait(); | 136 GetManifestAndWait(); |
| 110 EXPECT_FALSE(manifest().IsEmpty()); | 137 EXPECT_FALSE(manifest().IsEmpty()); |
| 138 EXPECT_EQ(0, ManifestBrowserTest::console_errors_count_); | |
| 111 } | 139 } |
| 112 | 140 |
| 113 // If a page changes manifest during its life-time, requesting the manifest | 141 // If a page changes manifest during its life-time, requesting the manifest |
| 114 // should return the current manifest. | 142 // should return the current manifest. |
| 115 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DynamicManifest) { | 143 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DynamicManifest) { |
| 116 GURL test_url = GetTestUrl("manifest", "dynamic-manifest.html"); | 144 GURL test_url = GetTestUrl("manifest", "dynamic-manifest.html"); |
| 117 | 145 |
| 118 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 146 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 119 shell()->LoadURL(test_url); | 147 shell()->LoadURL(test_url); |
| 120 navigation_observer.Wait(); | 148 navigation_observer.Wait(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 136 | 164 |
| 137 { | 165 { |
| 138 std::string manifest_url = | 166 std::string manifest_url = |
| 139 GetTestUrl("manifest", "empty-manifest.json").spec(); | 167 GetTestUrl("manifest", "empty-manifest.json").spec(); |
| 140 ASSERT_TRUE(content::ExecuteScript( | 168 ASSERT_TRUE(content::ExecuteScript( |
| 141 shell()->web_contents(), "setManifestTo('" + manifest_url + "')")); | 169 shell()->web_contents(), "setManifestTo('" + manifest_url + "')")); |
| 142 | 170 |
| 143 GetManifestAndWait(); | 171 GetManifestAndWait(); |
| 144 EXPECT_TRUE(manifest().IsEmpty()); | 172 EXPECT_TRUE(manifest().IsEmpty()); |
| 145 } | 173 } |
| 174 | |
| 175 EXPECT_EQ(0, ManifestBrowserTest::console_errors_count_); | |
| 146 } | 176 } |
| 147 | 177 |
| 148 // If a page's manifest lives in a different origin, it should follow the CORS | 178 // If a page's manifest lives in a different origin, it should follow the CORS |
| 149 // rules and requesting the manifest should return an empty manifest (unless the | 179 // rules and requesting the manifest should return an empty manifest (unless the |
| 150 // response contains CORS headers). | 180 // response contains CORS headers). |
| 151 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { | 181 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { |
| 152 scoped_ptr<net::test_server::EmbeddedTestServer> cors_embedded_test_server( | 182 scoped_ptr<net::test_server::EmbeddedTestServer> cors_embedded_test_server( |
| 153 new net::test_server::EmbeddedTestServer); | 183 new net::test_server::EmbeddedTestServer); |
| 154 | 184 |
| 155 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 185 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 156 ASSERT_TRUE(cors_embedded_test_server->InitializeAndWaitUntilReady()); | 186 ASSERT_TRUE(cors_embedded_test_server->InitializeAndWaitUntilReady()); |
| 157 ASSERT_NE(embedded_test_server()->port(), cors_embedded_test_server->port()); | 187 ASSERT_NE(embedded_test_server()->port(), cors_embedded_test_server->port()); |
| 158 | 188 |
| 159 GURL test_url = | 189 GURL test_url = |
| 160 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); | 190 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); |
| 161 | 191 |
| 162 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 192 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 163 shell()->LoadURL(test_url); | 193 shell()->LoadURL(test_url); |
| 164 navigation_observer.Wait(); | 194 navigation_observer.Wait(); |
| 165 | 195 |
| 166 std::string manifest_url = | 196 std::string manifest_url = |
| 167 cors_embedded_test_server->GetURL("/manifest/dummy-manifest.json").spec(); | 197 cors_embedded_test_server->GetURL("/manifest/dummy-manifest.json").spec(); |
| 168 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), | 198 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), |
| 169 "setManifestTo('" + manifest_url + "')")); | 199 "setManifestTo('" + manifest_url + "')")); |
| 170 | 200 |
| 171 GetManifestAndWait(); | 201 GetManifestAndWait(); |
| 172 EXPECT_TRUE(manifest().IsEmpty()); | 202 EXPECT_TRUE(manifest().IsEmpty()); |
| 203 | |
| 204 EXPECT_EQ(0, ManifestBrowserTest::console_errors_count_); | |
| 173 } | 205 } |
| 174 | 206 |
| 175 // If a page's manifest is in an unsecure origin while the page is in a secure | 207 // If a page's manifest is in an unsecure origin while the page is in a secure |
| 176 // origin, requesting the manifest should return the empty manifest. | 208 // origin, requesting the manifest should return the empty manifest. |
| 177 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { | 209 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { |
| 178 scoped_ptr<net::SpawnedTestServer> https_server(new net::SpawnedTestServer( | 210 scoped_ptr<net::SpawnedTestServer> https_server(new net::SpawnedTestServer( |
| 179 net::SpawnedTestServer::TYPE_HTTPS, | 211 net::SpawnedTestServer::TYPE_HTTPS, |
| 180 net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK), | 212 net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK), |
| 181 base::FilePath(FILE_PATH_LITERAL("content/test/data")))); | 213 base::FilePath(FILE_PATH_LITERAL("content/test/data")))); |
| 182 | 214 |
| 183 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 215 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 184 ASSERT_TRUE(https_server->Start()); | 216 ASSERT_TRUE(https_server->Start()); |
| 185 | 217 |
| 186 GURL test_url = | 218 GURL test_url = |
| 187 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); | 219 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); |
| 188 | 220 |
| 189 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 221 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 190 shell()->LoadURL(test_url); | 222 shell()->LoadURL(test_url); |
| 191 navigation_observer.Wait(); | 223 navigation_observer.Wait(); |
| 192 | 224 |
| 193 std::string manifest_url = | 225 std::string manifest_url = |
| 194 https_server->GetURL("/manifest/dummy-manifest.json").spec(); | 226 https_server->GetURL("/manifest/dummy-manifest.json").spec(); |
| 195 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), | 227 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), |
| 196 "setManifestTo('" + manifest_url + "')")); | 228 "setManifestTo('" + manifest_url + "')")); |
| 197 | 229 |
| 198 GetManifestAndWait(); | 230 GetManifestAndWait(); |
| 199 EXPECT_TRUE(manifest().IsEmpty()); | 231 EXPECT_TRUE(manifest().IsEmpty()); |
| 232 | |
| 233 EXPECT_EQ(0, ManifestBrowserTest::console_errors_count_); | |
| 234 } | |
| 235 | |
| 236 // If a page's manifest has some parsing errors, they should show up in the | |
| 237 // developer console. | |
| 238 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParsingErrorsManifest) { | |
| 239 GURL test_url = GetTestUrl("manifest", "parsing-errors.html"); | |
|
Peter Beverloo
2014/11/27 13:24:31
This file seems to be missing?
mlamouri (slow - plz ping)
2014/11/27 13:49:08
Done.
| |
| 240 | |
| 241 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
| 242 shell()->LoadURL(test_url); | |
| 243 navigation_observer.Wait(); | |
| 244 | |
| 245 GetManifestAndWait(); | |
| 246 EXPECT_TRUE(manifest().IsEmpty()); | |
| 247 EXPECT_EQ(6, ManifestBrowserTest::console_errors_count_); | |
| 200 } | 248 } |
| 201 | 249 |
| 202 } // namespace content | 250 } // namespace content |
| OLD | NEW |