| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/test/spawned_test_server/spawned_test_server.h" | 22 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 23 #include "net/url_request/test_url_fetcher_factory.h" | 23 #include "net/url_request/test_url_fetcher_factory.h" |
| 24 #include "net/url_request/url_fetcher_delegate.h" | 24 #include "net/url_request/url_fetcher_delegate.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const base::FilePath::CharType kTranslateRoot[] = | 28 const base::FilePath::CharType kTranslateRoot[] = |
| 29 FILE_PATH_LITERAL("chrome/test/data/translate"); | 29 FILE_PATH_LITERAL("chrome/test/data/translate"); |
| 30 const char kNonSecurePrefix[] = "files/translate/"; | 30 const char kNonSecurePrefix[] = "files/translate/"; |
| 31 const char kSecurePrefix[] = "files/"; | 31 const char kSecurePrefix[] = "files/"; |
| 32 const char kTargetPath[] = "fr_test.html"; | 32 const char kFrenchTestPath[] = "fr_test.html"; |
| 33 const char kRefreshMetaTagTestPath[] = "refresh_meta_tag.html"; |
| 34 const char kRefreshMetaTagAtOnloadTestPath[] = |
| 35 "refresh_meta_tag_at_onload.html"; |
| 36 const char kUpdateLocationTestPath[] = "update_location.html"; |
| 37 const char kUpdateLocationAtOnloadTestPath[] = "update_location_at_onload.html"; |
| 33 const char kMainScriptPath[] = "pseudo_main.js"; | 38 const char kMainScriptPath[] = "pseudo_main.js"; |
| 34 const char kElementMainScriptPath[] = "pseudo_element_main.js"; | 39 const char kElementMainScriptPath[] = "pseudo_element_main.js"; |
| 35 | 40 |
| 36 }; // namespace | 41 }; // namespace |
| 37 | 42 |
| 38 class TranslateBrowserTest : public InProcessBrowserTest { | 43 class TranslateBrowserTest : public InProcessBrowserTest { |
| 39 public: | 44 public: |
| 40 TranslateBrowserTest() | 45 TranslateBrowserTest() |
| 41 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, | 46 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, |
| 42 SSLOptions(SSLOptions::CERT_OK), | 47 SSLOptions(SSLOptions::CERT_OK), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 ASSERT_EQ(0U, infobar_service->infobar_count()); | 86 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 82 content::WindowedNotificationObserver infobar( | 87 content::WindowedNotificationObserver infobar( |
| 83 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 88 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 84 content::NotificationService::AllSources()); | 89 content::NotificationService::AllSources()); |
| 85 | 90 |
| 86 // Setup page title observer. | 91 // Setup page title observer. |
| 87 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 92 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
| 88 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 93 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
| 89 | 94 |
| 90 // Visit non-secure page which is going to be translated. | 95 // Visit non-secure page which is going to be translated. |
| 91 ui_test_utils::NavigateToURL(browser(), GetNonSecureURL(kTargetPath)); | 96 ui_test_utils::NavigateToURL(browser(), GetNonSecureURL(kFrenchTestPath)); |
| 92 | 97 |
| 93 // Wait for Chrome Translate infobar. | 98 // Wait for Chrome Translate infobar. |
| 94 infobar.Wait(); | 99 infobar.Wait(); |
| 95 | 100 |
| 96 // Perform Chrome Translate. | 101 // Perform Chrome Translate. |
| 97 InfoBarDelegate* delegate = infobar_service->infobar_at(0); | 102 InfoBarDelegate* delegate = infobar_service->infobar_at(0); |
| 98 ASSERT_TRUE(delegate); | 103 ASSERT_TRUE(delegate); |
| 99 TranslateInfoBarDelegate* translate = delegate->AsTranslateInfoBarDelegate(); | 104 TranslateInfoBarDelegate* translate = delegate->AsTranslateInfoBarDelegate(); |
| 100 ASSERT_TRUE(translate); | 105 ASSERT_TRUE(translate); |
| 101 translate->Translate(); | 106 translate->Translate(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 126 fetcher->set_url(fetcher->GetOriginalURL()); | 131 fetcher->set_url(fetcher->GetOriginalURL()); |
| 127 fetcher->set_response_code(net::HTTP_OK); | 132 fetcher->set_response_code(net::HTTP_OK); |
| 128 fetcher->SetResponseString(element_js); | 133 fetcher->SetResponseString(element_js); |
| 129 fetcher->delegate()->OnURLFetchComplete(fetcher); | 134 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 130 | 135 |
| 131 // Wait for the page title is changed after the test finished. | 136 // Wait for the page title is changed after the test finished. |
| 132 const string16 result = watcher.WaitAndGetTitle(); | 137 const string16 result = watcher.WaitAndGetTitle(); |
| 133 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 138 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
| 134 } | 139 } |
| 135 | 140 |
| 141 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) { |
| 142 ASSERT_TRUE(test_server()->Start()); |
| 143 |
| 144 content::WebContents* web_contents = |
| 145 browser()->tab_strip_model()->GetActiveWebContents(); |
| 146 ASSERT_TRUE(web_contents); |
| 147 |
| 148 // Check infobar count. |
| 149 InfoBarService* infobar_service = |
| 150 InfoBarService::FromWebContents(web_contents); |
| 151 ASSERT_TRUE(infobar_service); |
| 152 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 153 |
| 154 // Setup page title observer. |
| 155 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
| 156 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
| 157 |
| 158 // Visit a test page. |
| 159 ui_test_utils::NavigateToURL( |
| 160 browser(), |
| 161 GetNonSecureURL(kRefreshMetaTagTestPath)); |
| 162 |
| 163 // Wait for the page title is changed after the test finished. |
| 164 const string16 result = watcher.WaitAndGetTitle(); |
| 165 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
| 166 |
| 167 // Check there is not infobar. |
| 168 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 169 } |
| 170 |
| 171 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) { |
| 172 ASSERT_TRUE(test_server()->Start()); |
| 173 |
| 174 content::WebContents* web_contents = |
| 175 browser()->tab_strip_model()->GetActiveWebContents(); |
| 176 ASSERT_TRUE(web_contents); |
| 177 |
| 178 // Check infobar count. |
| 179 InfoBarService* infobar_service = |
| 180 InfoBarService::FromWebContents(web_contents); |
| 181 ASSERT_TRUE(infobar_service); |
| 182 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 183 |
| 184 // Setup page title observer. |
| 185 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
| 186 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
| 187 |
| 188 // Visit a test page. |
| 189 ui_test_utils::NavigateToURL( |
| 190 browser(), |
| 191 GetNonSecureURL(kRefreshMetaTagAtOnloadTestPath)); |
| 192 |
| 193 // Wait for the page title is changed after the test finished. |
| 194 const string16 result = watcher.WaitAndGetTitle(); |
| 195 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
| 196 |
| 197 // Check there is not infobar. |
| 198 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 199 } |
| 200 |
| 201 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { |
| 202 ASSERT_TRUE(test_server()->Start()); |
| 203 |
| 204 content::WebContents* web_contents = |
| 205 browser()->tab_strip_model()->GetActiveWebContents(); |
| 206 ASSERT_TRUE(web_contents); |
| 207 |
| 208 // Check infobar count. |
| 209 InfoBarService* infobar_service = |
| 210 InfoBarService::FromWebContents(web_contents); |
| 211 ASSERT_TRUE(infobar_service); |
| 212 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 213 |
| 214 // Setup page title observer. |
| 215 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
| 216 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
| 217 |
| 218 // Visit a test page. |
| 219 ui_test_utils::NavigateToURL( |
| 220 browser(), |
| 221 GetNonSecureURL(kUpdateLocationTestPath)); |
| 222 |
| 223 // Wait for the page title is changed after the test finished. |
| 224 const string16 result = watcher.WaitAndGetTitle(); |
| 225 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
| 226 |
| 227 // Check there is not infobar. |
| 228 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 229 } |
| 230 |
| 231 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { |
| 232 ASSERT_TRUE(test_server()->Start()); |
| 233 |
| 234 content::WebContents* web_contents = |
| 235 browser()->tab_strip_model()->GetActiveWebContents(); |
| 236 ASSERT_TRUE(web_contents); |
| 237 |
| 238 // Check infobar count. |
| 239 InfoBarService* infobar_service = |
| 240 InfoBarService::FromWebContents(web_contents); |
| 241 ASSERT_TRUE(infobar_service); |
| 242 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 243 |
| 244 // Setup page title observer. |
| 245 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
| 246 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
| 247 |
| 248 // Visit a test page. |
| 249 ui_test_utils::NavigateToURL( |
| 250 browser(), |
| 251 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); |
| 252 |
| 253 // Wait for the page title is changed after the test finished. |
| 254 const string16 result = watcher.WaitAndGetTitle(); |
| 255 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
| 256 |
| 257 // Check there is not infobar. |
| 258 ASSERT_EQ(0U, infobar_service->infobar_count()); |
| 259 } |
| 260 |
| 136 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ | 261 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ |
| OLD | NEW |