| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // A base class for tests below. | 94 // A base class for tests below. |
| 95 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { | 95 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { |
| 96 public: | 96 public: |
| 97 ExtensionWebstorePrivateApiTest() {} | 97 ExtensionWebstorePrivateApiTest() {} |
| 98 ~ExtensionWebstorePrivateApiTest() override {} | 98 ~ExtensionWebstorePrivateApiTest() override {} |
| 99 | 99 |
| 100 void SetUpCommandLine(base::CommandLine* command_line) override { | 100 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 101 ExtensionApiTest::SetUpCommandLine(command_line); | 101 ExtensionApiTest::SetUpCommandLine(command_line); |
| 102 command_line->AppendSwitchASCII( | 102 command_line->AppendSwitchASCII( |
| 103 switches::kAppsGalleryURL, | 103 switches::kAppsGalleryURL, |
| 104 "http://www.example.com/files/extensions/api_test"); | 104 "http://www.example.com/extensions/api_test"); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void SetUpInProcessBrowserTestFixture() override { | 107 void SetUpInProcessBrowserTestFixture() override { |
| 108 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 108 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 109 | 109 |
| 110 // Start up the test server and get us ready for calling the install | 110 // Start up the test server and get us ready for calling the install |
| 111 // API functions. | 111 // API functions. |
| 112 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 112 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 113 ASSERT_TRUE(StartSpawnedTestServer()); | 113 ASSERT_TRUE(StartTestServer()); |
| 114 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests(); | 114 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void SetUpOnMainThread() override { | 117 void SetUpOnMainThread() override { |
| 118 ExtensionApiTest::SetUpOnMainThread(); | 118 ExtensionApiTest::SetUpOnMainThread(); |
| 119 | 119 |
| 120 auto_confirm_install_.reset( | 120 auto_confirm_install_.reset( |
| 121 new ScopedTestDialogAutoConfirm(ScopedTestDialogAutoConfirm::ACCEPT)); | 121 new ScopedTestDialogAutoConfirm(ScopedTestDialogAutoConfirm::ACCEPT)); |
| 122 | 122 |
| 123 ASSERT_TRUE(webstore_install_dir_.CreateUniqueTempDir()); | 123 ASSERT_TRUE(webstore_install_dir_.CreateUniqueTempDir()); |
| 124 webstore_install_dir_copy_ = webstore_install_dir_.path(); | 124 webstore_install_dir_copy_ = webstore_install_dir_.path(); |
| 125 WebstoreInstaller::SetDownloadDirectoryForTests( | 125 WebstoreInstaller::SetDownloadDirectoryForTests( |
| 126 &webstore_install_dir_copy_); | 126 &webstore_install_dir_copy_); |
| 127 } | 127 } |
| 128 | 128 |
| 129 protected: | 129 protected: |
| 130 // Returns a test server URL, but with host 'www.example.com' so it matches | 130 // Returns a test server URL, but with host 'www.example.com' so it matches |
| 131 // the web store app's extent that we set up via command line flags. | 131 // the web store app's extent that we set up via command line flags. |
| 132 GURL DoGetTestServerURL(const std::string& path) { | 132 GURL DoGetTestServerURL(const std::string& path) { |
| 133 GURL url = test_server()->GetURL(path); | 133 GURL url = embedded_test_server()->GetURL(path); |
| 134 | 134 |
| 135 // Replace the host with 'www.example.com' so it matches the web store | 135 // Replace the host with 'www.example.com' so it matches the web store |
| 136 // app's extent. | 136 // app's extent. |
| 137 GURL::Replacements replace_host; | 137 GURL::Replacements replace_host; |
| 138 replace_host.SetHostStr("www.example.com"); | 138 replace_host.SetHostStr("www.example.com"); |
| 139 | 139 |
| 140 return url.ReplaceComponents(replace_host); | 140 return url.ReplaceComponents(replace_host); |
| 141 } | 141 } |
| 142 | 142 |
| 143 virtual GURL GetTestServerURL(const std::string& path) { | 143 virtual GURL GetTestServerURL(const std::string& path) { |
| 144 return DoGetTestServerURL( | 144 return DoGetTestServerURL( |
| 145 std::string("files/extensions/api_test/webstore_private/") + path); | 145 std::string("/extensions/api_test/webstore_private/") + path); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // Navigates to |page| and runs the Extension API test there. Any downloads | 148 // Navigates to |page| and runs the Extension API test there. Any downloads |
| 149 // of extensions will return the contents of |crx_file|. | 149 // of extensions will return the contents of |crx_file|. |
| 150 bool RunInstallTest(const std::string& page, const std::string& crx_file) { | 150 bool RunInstallTest(const std::string& page, const std::string& crx_file) { |
| 151 #if defined(OS_WIN) && !defined(NDEBUG) | 151 #if defined(OS_WIN) && !defined(NDEBUG) |
| 152 // See http://crbug.com/177163 for details. | 152 // See http://crbug.com/177163 for details. |
| 153 return true; | 153 return true; |
| 154 #else | 154 #else |
| 155 GURL crx_url = GetTestServerURL(crx_file); | 155 GURL crx_url = GetTestServerURL(crx_file); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 182 | 182 |
| 183 // Test cases for webstore origin frame blocking. | 183 // Test cases for webstore origin frame blocking. |
| 184 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into | 184 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into |
| 185 // Chromium, see crbug.com/226018. | 185 // Chromium, see crbug.com/226018. |
| 186 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 186 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
| 187 DISABLED_FrameWebstorePageBlocked) { | 187 DISABLED_FrameWebstorePageBlocked) { |
| 188 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); | 188 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); |
| 189 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); | 189 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); |
| 190 content::TitleWatcher watcher(GetWebContents(), expected_title); | 190 content::TitleWatcher watcher(GetWebContents(), expected_title); |
| 191 watcher.AlsoWaitForTitle(failure_title); | 191 watcher.AlsoWaitForTitle(failure_title); |
| 192 GURL url = test_server()->GetURL( | 192 GURL url = embedded_test_server()->GetURL( |
| 193 "files/extensions/api_test/webstore_private/noframe.html"); | 193 "/extensions/api_test/webstore_private/noframe.html"); |
| 194 ui_test_utils::NavigateToURL(browser(), url); | 194 ui_test_utils::NavigateToURL(browser(), url); |
| 195 base::string16 final_title = watcher.WaitAndGetTitle(); | 195 base::string16 final_title = watcher.WaitAndGetTitle(); |
| 196 EXPECT_EQ(expected_title, final_title); | 196 EXPECT_EQ(expected_title, final_title); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into | 199 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into |
| 200 // Chromium, see crbug.com/226018. | 200 // Chromium, see crbug.com/226018. |
| 201 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 201 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
| 202 DISABLED_FrameErrorPageBlocked) { | 202 DISABLED_FrameErrorPageBlocked) { |
| 203 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); | 203 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); |
| 204 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); | 204 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); |
| 205 content::TitleWatcher watcher(GetWebContents(), expected_title); | 205 content::TitleWatcher watcher(GetWebContents(), expected_title); |
| 206 watcher.AlsoWaitForTitle(failure_title); | 206 watcher.AlsoWaitForTitle(failure_title); |
| 207 GURL url = test_server()->GetURL( | 207 GURL url = embedded_test_server()->GetURL( |
| 208 "files/extensions/api_test/webstore_private/noframe2.html"); | 208 "/extensions/api_test/webstore_private/noframe2.html"); |
| 209 ui_test_utils::NavigateToURL(browser(), url); | 209 ui_test_utils::NavigateToURL(browser(), url); |
| 210 base::string16 final_title = watcher.WaitAndGetTitle(); | 210 base::string16 final_title = watcher.WaitAndGetTitle(); |
| 211 EXPECT_EQ(expected_title, final_title); | 211 EXPECT_EQ(expected_title, final_title); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Test cases where the user accepts the install confirmation dialog. | 214 // Test cases where the user accepts the install confirmation dialog. |
| 215 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) { | 215 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) { |
| 216 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx")); | 216 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx")); |
| 217 } | 217 } |
| 218 | 218 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing | 440 // CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing |
| 441 // crx file). | 441 // crx file). |
| 442 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) { | 442 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) { |
| 443 extensions::BundleInstaller::SetAutoApproveForTesting(true); | 443 extensions::BundleInstaller::SetAutoApproveForTesting(true); |
| 444 | 444 |
| 445 ASSERT_TRUE( | 445 ASSERT_TRUE( |
| 446 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec())); | 446 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec())); |
| 447 } | 447 } |
| 448 | 448 |
| 449 } // namespace extensions | 449 } // namespace extensions |
| OLD | NEW |