Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
27 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
28 #include "extensions/browser/api/management/management_api.h" 28 #include "extensions/browser/api/management/management_api.h"
29 #include "extensions/browser/extension_dialog_auto_confirm.h" 29 #include "extensions/browser/extension_dialog_auto_confirm.h"
30 #include "extensions/browser/extension_system.h" 30 #include "extensions/browser/extension_system.h"
31 #include "extensions/browser/install/extension_install_ui.h" 31 #include "extensions/browser/install/extension_install_ui.h"
32 #include "gpu/config/gpu_feature_type.h" 32 #include "gpu/config/gpu_feature_type.h"
33 #include "gpu/config/gpu_info.h" 33 #include "gpu/config/gpu_info.h"
34 #include "net/dns/mock_host_resolver.h" 34 #include "net/dns/mock_host_resolver.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h"
35 #include "ui/gl/gl_switches.h" 36 #include "ui/gl/gl_switches.h"
36 37
37 using gpu::GpuFeatureType; 38 using gpu::GpuFeatureType;
38 39
39 namespace utils = extension_function_test_utils; 40 namespace utils = extension_function_test_utils;
40 41
41 namespace extensions { 42 namespace extensions {
42 43
43 namespace { 44 namespace {
44 45
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // A base class for tests below. 95 // A base class for tests below.
95 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { 96 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest {
96 public: 97 public:
97 ExtensionWebstorePrivateApiTest() {} 98 ExtensionWebstorePrivateApiTest() {}
98 ~ExtensionWebstorePrivateApiTest() override {} 99 ~ExtensionWebstorePrivateApiTest() override {}
99 100
100 void SetUpCommandLine(base::CommandLine* command_line) override { 101 void SetUpCommandLine(base::CommandLine* command_line) override {
101 ExtensionApiTest::SetUpCommandLine(command_line); 102 ExtensionApiTest::SetUpCommandLine(command_line);
102 command_line->AppendSwitchASCII( 103 command_line->AppendSwitchASCII(
103 switches::kAppsGalleryURL, 104 switches::kAppsGalleryURL,
104 "http://www.example.com/files/extensions/api_test"); 105 "http://www.example.com/extensions/api_test");
105 } 106 }
106 107
107 void SetUpInProcessBrowserTestFixture() override { 108 void SetUpInProcessBrowserTestFixture() override {
108 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); 109 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
109 110
110 // Start up the test server and get us ready for calling the install 111 // Start up the test server and get us ready for calling the install
111 // API functions. 112 // API functions.
112 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 113 host_resolver()->AddRule("www.example.com", "127.0.0.1");
113 ASSERT_TRUE(StartSpawnedTestServer()); 114 ASSERT_TRUE(StartEmbeddedTestServer());
114 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests(); 115 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests();
115 } 116 }
116 117
117 void SetUpOnMainThread() override { 118 void SetUpOnMainThread() override {
118 ExtensionApiTest::SetUpOnMainThread(); 119 ExtensionApiTest::SetUpOnMainThread();
119 120
120 auto_confirm_install_.reset( 121 auto_confirm_install_.reset(
121 new ScopedTestDialogAutoConfirm(ScopedTestDialogAutoConfirm::ACCEPT)); 122 new ScopedTestDialogAutoConfirm(ScopedTestDialogAutoConfirm::ACCEPT));
122 123
123 ASSERT_TRUE(webstore_install_dir_.CreateUniqueTempDir()); 124 ASSERT_TRUE(webstore_install_dir_.CreateUniqueTempDir());
124 webstore_install_dir_copy_ = webstore_install_dir_.path(); 125 webstore_install_dir_copy_ = webstore_install_dir_.path();
125 WebstoreInstaller::SetDownloadDirectoryForTests( 126 WebstoreInstaller::SetDownloadDirectoryForTests(
126 &webstore_install_dir_copy_); 127 &webstore_install_dir_copy_);
127 } 128 }
128 129
129 protected: 130 protected:
130 // Returns a test server URL, but with host 'www.example.com' so it matches 131 // 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. 132 // the web store app's extent that we set up via command line flags.
132 GURL DoGetTestServerURL(const std::string& path) { 133 GURL DoGetTestServerURL(const std::string& path) {
133 GURL url = test_server()->GetURL(path); 134 GURL url = embedded_test_server()->GetURL(path);
134 135
135 // Replace the host with 'www.example.com' so it matches the web store 136 // Replace the host with 'www.example.com' so it matches the web store
136 // app's extent. 137 // app's extent.
137 GURL::Replacements replace_host; 138 GURL::Replacements replace_host;
138 replace_host.SetHostStr("www.example.com"); 139 replace_host.SetHostStr("www.example.com");
139 140
140 return url.ReplaceComponents(replace_host); 141 return url.ReplaceComponents(replace_host);
141 } 142 }
142 143
143 virtual GURL GetTestServerURL(const std::string& path) { 144 virtual GURL GetTestServerURL(const std::string& path) {
144 return DoGetTestServerURL( 145 return DoGetTestServerURL(
145 std::string("files/extensions/api_test/webstore_private/") + path); 146 std::string("/extensions/api_test/webstore_private/") + path);
146 } 147 }
147 148
148 // Navigates to |page| and runs the Extension API test there. Any downloads 149 // Navigates to |page| and runs the Extension API test there. Any downloads
149 // of extensions will return the contents of |crx_file|. 150 // of extensions will return the contents of |crx_file|.
150 bool RunInstallTest(const std::string& page, const std::string& crx_file) { 151 bool RunInstallTest(const std::string& page, const std::string& crx_file) {
151 #if defined(OS_WIN) && !defined(NDEBUG) 152 #if defined(OS_WIN) && !defined(NDEBUG)
152 // See http://crbug.com/177163 for details. 153 // See http://crbug.com/177163 for details.
153 return true; 154 return true;
154 #else 155 #else
155 GURL crx_url = GetTestServerURL(crx_file); 156 GURL crx_url = GetTestServerURL(crx_file);
(...skipping 26 matching lines...) Expand all
182 183
183 // Test cases for webstore origin frame blocking. 184 // Test cases for webstore origin frame blocking.
184 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into 185 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into
185 // Chromium, see crbug.com/226018. 186 // Chromium, see crbug.com/226018.
186 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, 187 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
187 DISABLED_FrameWebstorePageBlocked) { 188 DISABLED_FrameWebstorePageBlocked) {
188 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); 189 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank");
189 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); 190 base::string16 failure_title = base::UTF8ToUTF16("FAIL");
190 content::TitleWatcher watcher(GetWebContents(), expected_title); 191 content::TitleWatcher watcher(GetWebContents(), expected_title);
191 watcher.AlsoWaitForTitle(failure_title); 192 watcher.AlsoWaitForTitle(failure_title);
192 GURL url = test_server()->GetURL( 193 GURL url = embedded_test_server()->GetURL(
193 "files/extensions/api_test/webstore_private/noframe.html"); 194 "/extensions/api_test/webstore_private/noframe.html");
194 ui_test_utils::NavigateToURL(browser(), url); 195 ui_test_utils::NavigateToURL(browser(), url);
195 base::string16 final_title = watcher.WaitAndGetTitle(); 196 base::string16 final_title = watcher.WaitAndGetTitle();
196 EXPECT_EQ(expected_title, final_title); 197 EXPECT_EQ(expected_title, final_title);
197 } 198 }
198 199
199 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into 200 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into
200 // Chromium, see crbug.com/226018. 201 // Chromium, see crbug.com/226018.
201 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, 202 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
202 DISABLED_FrameErrorPageBlocked) { 203 DISABLED_FrameErrorPageBlocked) {
203 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); 204 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank");
204 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); 205 base::string16 failure_title = base::UTF8ToUTF16("FAIL");
205 content::TitleWatcher watcher(GetWebContents(), expected_title); 206 content::TitleWatcher watcher(GetWebContents(), expected_title);
206 watcher.AlsoWaitForTitle(failure_title); 207 watcher.AlsoWaitForTitle(failure_title);
207 GURL url = test_server()->GetURL( 208 GURL url = embedded_test_server()->GetURL(
208 "files/extensions/api_test/webstore_private/noframe2.html"); 209 "/extensions/api_test/webstore_private/noframe2.html");
209 ui_test_utils::NavigateToURL(browser(), url); 210 ui_test_utils::NavigateToURL(browser(), url);
210 base::string16 final_title = watcher.WaitAndGetTitle(); 211 base::string16 final_title = watcher.WaitAndGetTitle();
211 EXPECT_EQ(expected_title, final_title); 212 EXPECT_EQ(expected_title, final_title);
212 } 213 }
213 214
214 // Test cases where the user accepts the install confirmation dialog. 215 // Test cases where the user accepts the install confirmation dialog.
215 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) { 216 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) {
216 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx")); 217 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx"));
217 } 218 }
218 219
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing 441 // CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing
441 // crx file). 442 // crx file).
442 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) { 443 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) {
443 extensions::BundleInstaller::SetAutoApproveForTesting(true); 444 extensions::BundleInstaller::SetAutoApproveForTesting(true);
444 445
445 ASSERT_TRUE( 446 ASSERT_TRUE(
446 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec())); 447 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec()));
447 } 448 }
448 449
449 } // namespace extensions 450 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_test.cc ('k') | chrome/browser/extensions/app_process_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698