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

Side by Side Diff: chrome/browser/translate/translate_browsertest.cc

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase bug. 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // This entire test suite relies on the translate infobar which has been removed 5 // This entire test suite relies on the translate infobar which has been removed
6 // from Aura. The file should be ported to use the bubble. 6 // from Aura. The file should be ported to use the bubble.
7 #if !defined(USE_AURA) 7 #if !defined(USE_AURA)
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/infobars/core/infobar.h" 23 #include "components/infobars/core/infobar.h"
24 #include "components/translate/core/browser/translate_infobar_delegate.h" 24 #include "components/translate/core/browser/translate_infobar_delegate.h"
25 #include "components/translate/core/browser/translate_manager.h" 25 #include "components/translate/core/browser/translate_manager.h"
26 #include "components/translate/core/browser/translate_script.h" 26 #include "components/translate/core/browser/translate_script.h"
27 #include "components/translate/core/common/translate_switches.h" 27 #include "components/translate/core/common/translate_switches.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/public/test/browser_test_utils.h" 29 #include "content/public/test/browser_test_utils.h"
30 #include "net/http/http_status_code.h" 30 #include "net/http/http_status_code.h"
31 #include "net/test/embedded_test_server/embedded_test_server.h" 31 #include "net/test/embedded_test_server/embedded_test_server.h"
32 #include "net/test/spawned_test_server/spawned_test_server.h"
33 #include "net/url_request/test_url_fetcher_factory.h" 32 #include "net/url_request/test_url_fetcher_factory.h"
34 #include "net/url_request/url_fetcher_delegate.h" 33 #include "net/url_request/url_fetcher_delegate.h"
35 34
36 namespace { 35 namespace {
37 36
38 const base::FilePath::CharType kTranslateRoot[] = 37 const base::FilePath::CharType kTranslateRoot[] =
39 FILE_PATH_LITERAL("chrome/test/data/translate"); 38 FILE_PATH_LITERAL("chrome/test/data/translate");
40 const char kNonSecurePrefix[] = "translate/";
41 const char kSecurePrefix[] = "files/";
42 const char kFrenchTestPath[] = "/fr_test.html"; 39 const char kFrenchTestPath[] = "/fr_test.html";
43 const char kBasicFrenchTestPath[] = "/basic_fr_test.html"; 40 const char kBasicFrenchTestPath[] = "/basic_fr_test.html";
44 const char kRefreshMetaTagTestPath[] = "/refresh_meta_tag.html"; 41 const char kRefreshMetaTagTestPath[] = "/refresh_meta_tag.html";
45 const char kRefreshMetaTagCaseInsensitiveTestPath[] = 42 const char kRefreshMetaTagCaseInsensitiveTestPath[] =
46 "/refresh_meta_tag_casei.html"; 43 "/refresh_meta_tag_casei.html";
47 const char kRefreshMetaTagAtOnloadTestPath[] = 44 const char kRefreshMetaTagAtOnloadTestPath[] =
48 "/refresh_meta_tag_at_onload.html"; 45 "/refresh_meta_tag_at_onload.html";
49 const char kUpdateLocationTestPath[] = "/update_location.html"; 46 const char kUpdateLocationTestPath[] = "/update_location.html";
50 const char kUpdateLocationAtOnloadTestPath[] = 47 const char kUpdateLocationAtOnloadTestPath[] =
51 "/update_location_at_onload.html"; 48 "/update_location_at_onload.html";
52 const char kMainScriptPath[] = "/pseudo_main.js"; 49 const char kMainScriptPath[] = "/pseudo_main.js";
53 const char kElementMainScriptPath[] = "/pseudo_element_main.js"; 50 const char kElementMainScriptPath[] = "/pseudo_element_main.js";
54 51
55 }; // namespace 52 }; // namespace
56 53
57 // Basic translate browser test with an embedded non-secure test server. 54 // Basic translate browser test with an embedded non-secure test server.
58 class TranslateBaseBrowserTest : public InProcessBrowserTest { 55 class TranslateBaseBrowserTest : public InProcessBrowserTest {
59 public: 56 public:
60 TranslateBaseBrowserTest() {} 57 TranslateBaseBrowserTest() {}
61 58
62 void SetUp() override { 59 void SetUp() override {
63 set_open_about_blank_on_browser_launch(false); 60 set_open_about_blank_on_browser_launch(false);
64 translate::TranslateManager::SetIgnoreMissingKeyForTesting(true); 61 translate::TranslateManager::SetIgnoreMissingKeyForTesting(true);
65 InProcessBrowserTest::SetUp(); 62 InProcessBrowserTest::SetUp();
66 } 63 }
67 64
68 void SetUpOnMainThread() override { 65 void SetUpOnMainThread() override {
69 net::test_server::EmbeddedTestServer* test_server = embedded_test_server(); 66 net::EmbeddedTestServer* test_server = embedded_test_server();
70 base::FilePath test_data_dir; 67 test_server->ServeFilesFromSourceDirectory(kTranslateRoot);
71 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 68 ASSERT_TRUE(test_server->Start());
72 test_data_dir = test_data_dir.AppendASCII(kNonSecurePrefix);
73 test_server->ServeFilesFromDirectory(test_data_dir);
74 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady());
75 InProcessBrowserTest::SetUpOnMainThread(); 69 InProcessBrowserTest::SetUpOnMainThread();
76 } 70 }
77 71
78 protected: 72 protected:
79 GURL GetNonSecureURL(const std::string& path) const { 73 GURL GetNonSecureURL(const std::string& path) const {
80 return embedded_test_server()->GetURL(path); 74 return embedded_test_server()->GetURL(path);
81 } 75 }
82 76
83 private: 77 private:
84 DISALLOW_COPY_AND_ASSIGN(TranslateBaseBrowserTest); 78 DISALLOW_COPY_AND_ASSIGN(TranslateBaseBrowserTest);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 184 }
191 185
192 private: 186 private:
193 InfoBarService* infobar_service_; 187 InfoBarService* infobar_service_;
194 }; 188 };
195 189
196 // Translate browser test with a seperate secure server setup. 190 // Translate browser test with a seperate secure server setup.
197 class TranslateWithSecureServerBrowserTest : public TranslateBrowserTest { 191 class TranslateWithSecureServerBrowserTest : public TranslateBrowserTest {
198 public: 192 public:
199 TranslateWithSecureServerBrowserTest() 193 TranslateWithSecureServerBrowserTest()
200 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, 194 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
201 SSLOptions(SSLOptions::CERT_OK), 195 https_server_.ServeFilesFromSourceDirectory(kTranslateRoot);
202 base::FilePath(kTranslateRoot)) {} 196 }
203 197
204 void SetUpCommandLine(base::CommandLine* command_line) override { 198 void SetUpCommandLine(base::CommandLine* command_line) override {
205 ASSERT_TRUE(https_server_.Start()); 199 ASSERT_TRUE(https_server_.Start());
206 // Setup alternate security origin for testing in order to allow XHR against 200 // Setup alternate security origin for testing in order to allow XHR against
207 // local test server. Note that this flag shows a confirm infobar in tests. 201 // local test server. Note that this flag shows a confirm infobar in tests.
208 GURL base_url = GetSecureURL(""); 202 GURL base_url = GetSecureURL("/");
209 command_line->AppendSwitchASCII( 203 command_line->AppendSwitchASCII(
210 translate::switches::kTranslateSecurityOrigin, 204 translate::switches::kTranslateSecurityOrigin,
211 base_url.GetOrigin().spec()); 205 base_url.GetOrigin().spec());
212 TranslateBrowserTest::SetUpCommandLine(command_line); 206 TranslateBrowserTest::SetUpCommandLine(command_line);
213 } 207 }
214 208
215 protected: 209 protected:
216 GURL GetSecureURL(const std::string& path) const { 210 GURL GetSecureURL(const std::string& path) const {
217 std::string prefix(kSecurePrefix); 211 return https_server_.GetURL(path);
218 return https_server_.GetURL(prefix + path);
219 } 212 }
220 213
221 private: 214 private:
222 net::SpawnedTestServer https_server_; 215 net::EmbeddedTestServer https_server_;
223
224 typedef net::SpawnedTestServer::SSLOptions SSLOptions;
225 216
226 DISALLOW_COPY_AND_ASSIGN(TranslateWithSecureServerBrowserTest); 217 DISALLOW_COPY_AND_ASSIGN(TranslateWithSecureServerBrowserTest);
227 }; 218 };
228 219
229 IN_PROC_BROWSER_TEST_F(TranslateWithSecureServerBrowserTest, 220 IN_PROC_BROWSER_TEST_F(TranslateWithSecureServerBrowserTest,
230 TranslateInIsolatedWorld) { 221 TranslateInIsolatedWorld) {
231 net::TestURLFetcherFactory factory; 222 net::TestURLFetcherFactory factory;
232 ASSERT_NO_FATAL_FAILURE(CheckForTranslateUI(kFrenchTestPath, true)); 223 ASSERT_NO_FATAL_FAILURE(CheckForTranslateUI(kFrenchTestPath, true));
233 224
234 // Setup page title observer. 225 // Setup page title observer.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { 285 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) {
295 ASSERT_NO_FATAL_FAILURE(CheckForTranslateUI( 286 ASSERT_NO_FATAL_FAILURE(CheckForTranslateUI(
296 kUpdateLocationTestPath, false)); 287 kUpdateLocationTestPath, false));
297 } 288 }
298 289
299 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { 290 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) {
300 ASSERT_NO_FATAL_FAILURE(CheckForTranslateUI( 291 ASSERT_NO_FATAL_FAILURE(CheckForTranslateUI(
301 kUpdateLocationAtOnloadTestPath, false)); 292 kUpdateLocationAtOnloadTestPath, false));
302 } 293 }
303 #endif // !defined(USE_AURA) 294 #endif // !defined(USE_AURA)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698