OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "content/public/browser/web_contents.h" |
| 7 #include "content/public/common/content_switches.h" |
| 8 #include "content/public/common/manifest.h" |
| 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/content_browser_test.h" |
| 11 #include "content/public/test/content_browser_test_utils.h" |
| 12 #include "content/public/test/test_navigation_observer.h" |
| 13 #include "content/shell/browser/shell.h" |
| 14 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class ManifestBrowserTest : public ContentBrowserTest { |
| 19 protected: |
| 20 ManifestBrowserTest() {} |
| 21 virtual ~ManifestBrowserTest() {} |
| 22 |
| 23 void GetManifestAndWait() { |
| 24 shell()->web_contents()->GetManifest( |
| 25 base::Bind(&ManifestBrowserTest::OnGetManifest, |
| 26 base::Unretained(this))); |
| 27 |
| 28 message_loop_runner_ = new MessageLoopRunner(); |
| 29 message_loop_runner_->Run(); |
| 30 } |
| 31 |
| 32 void OnGetManifest(const Manifest& manifest) { |
| 33 manifest_ = manifest; |
| 34 message_loop_runner_->Quit(); |
| 35 } |
| 36 |
| 37 const Manifest& manifest() const { |
| 38 return manifest_; |
| 39 } |
| 40 |
| 41 private: |
| 42 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 43 Manifest manifest_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); |
| 46 }; |
| 47 |
| 48 // If a page has no manifest, requesting a manifest should return the empty |
| 49 // manifest. |
| 50 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoManifest) { |
| 51 GURL test_url = GetTestUrl("manifest", "no-manifest.html"); |
| 52 |
| 53 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 54 shell()->LoadURL(test_url); |
| 55 navigation_observer.Wait(); |
| 56 |
| 57 GetManifestAndWait(); |
| 58 EXPECT_TRUE(manifest().IsEmpty()); |
| 59 } |
| 60 |
| 61 // If a page manifest points to a 404 URL, requesting the manifest should return |
| 62 // the empty manifest. |
| 63 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, 404Manifest) { |
| 64 GURL test_url = GetTestUrl("manifest", "404-manifest.html"); |
| 65 |
| 66 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 67 shell()->LoadURL(test_url); |
| 68 navigation_observer.Wait(); |
| 69 |
| 70 GetManifestAndWait(); |
| 71 EXPECT_TRUE(manifest().IsEmpty()); |
| 72 } |
| 73 |
| 74 // If a page has an empty manifest, requesting the manifest should return the |
| 75 // empty manifest. |
| 76 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, EmptyManifest) { |
| 77 GURL test_url = GetTestUrl("manifest", "empty-manifest.html"); |
| 78 |
| 79 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 80 shell()->LoadURL(test_url); |
| 81 navigation_observer.Wait(); |
| 82 |
| 83 GetManifestAndWait(); |
| 84 EXPECT_TRUE(manifest().IsEmpty()); |
| 85 } |
| 86 |
| 87 // If a page's manifest can't be parsed correctly, requesting the manifest |
| 88 // should return an empty manifest. |
| 89 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParseErrorManifest) { |
| 90 GURL test_url = GetTestUrl("manifest", "parse-error-manifest.html"); |
| 91 |
| 92 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 93 shell()->LoadURL(test_url); |
| 94 navigation_observer.Wait(); |
| 95 |
| 96 GetManifestAndWait(); |
| 97 EXPECT_TRUE(manifest().IsEmpty()); |
| 98 } |
| 99 |
| 100 // If a page has a manifest that can be fetched and parsed, requesting the |
| 101 // manifest should return a properly filled manifest. |
| 102 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DummyManifest) { |
| 103 GURL test_url = GetTestUrl("manifest", "dummy-manifest.html"); |
| 104 |
| 105 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 106 shell()->LoadURL(test_url); |
| 107 navigation_observer.Wait(); |
| 108 |
| 109 GetManifestAndWait(); |
| 110 EXPECT_FALSE(manifest().IsEmpty()); |
| 111 } |
| 112 |
| 113 // If a page changes manifest during its life-time, requesting the manifest |
| 114 // should return the current manifest. |
| 115 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DynamicManifest) { |
| 116 GURL test_url = GetTestUrl("manifest", "dynamic-manifest.html"); |
| 117 |
| 118 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 119 shell()->LoadURL(test_url); |
| 120 navigation_observer.Wait(); |
| 121 |
| 122 { |
| 123 GetManifestAndWait(); |
| 124 EXPECT_TRUE(manifest().IsEmpty()); |
| 125 } |
| 126 |
| 127 { |
| 128 std::string manifest_url = |
| 129 GetTestUrl("manifest", "dummy-manifest.json").spec(); |
| 130 ASSERT_TRUE(content::ExecuteScript( |
| 131 shell()->web_contents(), "setManifestTo('" + manifest_url + "')")); |
| 132 |
| 133 GetManifestAndWait(); |
| 134 EXPECT_FALSE(manifest().IsEmpty()); |
| 135 } |
| 136 |
| 137 { |
| 138 std::string manifest_url = |
| 139 GetTestUrl("manifest", "empty-manifest.json").spec(); |
| 140 ASSERT_TRUE(content::ExecuteScript( |
| 141 shell()->web_contents(), "setManifestTo('" + manifest_url + "')")); |
| 142 |
| 143 GetManifestAndWait(); |
| 144 EXPECT_TRUE(manifest().IsEmpty()); |
| 145 } |
| 146 } |
| 147 |
| 148 // 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 |
| 150 // response contains CORS headers). |
| 151 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { |
| 152 scoped_ptr<net::test_server::EmbeddedTestServer> cors_embedded_test_server( |
| 153 new net::test_server::EmbeddedTestServer); |
| 154 |
| 155 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 156 ASSERT_TRUE(cors_embedded_test_server->InitializeAndWaitUntilReady()); |
| 157 ASSERT_NE(embedded_test_server()->port(), cors_embedded_test_server->port()); |
| 158 |
| 159 GURL test_url = |
| 160 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); |
| 161 |
| 162 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 163 shell()->LoadURL(test_url); |
| 164 navigation_observer.Wait(); |
| 165 |
| 166 std::string manifest_url = |
| 167 cors_embedded_test_server->GetURL("/manifest/dummy-manifest.json").spec(); |
| 168 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), |
| 169 "setManifestTo('" + manifest_url + "')")); |
| 170 |
| 171 GetManifestAndWait(); |
| 172 EXPECT_TRUE(manifest().IsEmpty()); |
| 173 } |
| 174 |
| 175 // 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. |
| 177 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { |
| 178 scoped_ptr<net::SpawnedTestServer> https_server(new net::SpawnedTestServer( |
| 179 net::SpawnedTestServer::TYPE_HTTPS, |
| 180 net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK), |
| 181 base::FilePath(FILE_PATH_LITERAL("content/test/data")))); |
| 182 |
| 183 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 184 ASSERT_TRUE(https_server->Start()); |
| 185 |
| 186 GURL test_url = |
| 187 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); |
| 188 |
| 189 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 190 shell()->LoadURL(test_url); |
| 191 navigation_observer.Wait(); |
| 192 |
| 193 std::string manifest_url = |
| 194 https_server->GetURL("/manifest/dummy-manifest.json").spec(); |
| 195 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), |
| 196 "setManifestTo('" + manifest_url + "')")); |
| 197 |
| 198 GetManifestAndWait(); |
| 199 EXPECT_TRUE(manifest().IsEmpty()); |
| 200 } |
| 201 |
| 202 } // namespace content |
OLD | NEW |