Commit 9d6bc5ec authored by Anthony Cui's avatar Anthony Cui Committed by Commit Bot

Update browser tests to use embedded test server

URLs with a file scheme ("file://") are not translated, change 2444549
moves this check from Android into shared code. As such, browser tests
that load a local file to test translation should be updated to use the
embedded test server instead.

Bug: 1127094
Change-Id: Ib02a33844da02dff205e8acf9cc233c53cdcaa1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454692
Commit-Queue: Anthony Cui <cuianthony@chromium.org>
Reviewed-by: default avatarScott Little <sclittle@chromium.org>
Reviewed-by: default avatarMegan Jablonski <megjablon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816704}
parent 87f7cffc
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/translate/core/browser/translate_manager.h" #include "components/translate/core/browser/translate_manager.h"
#include "components/translate/core/common/translate_switches.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
...@@ -40,9 +41,25 @@ class TranslateBubbleViewBrowserTest : public InProcessBrowserTest { ...@@ -40,9 +41,25 @@ class TranslateBubbleViewBrowserTest : public InProcessBrowserTest {
void SetUp() override { void SetUp() override {
set_open_about_blank_on_browser_launch(true); set_open_about_blank_on_browser_launch(true);
TranslateManager::SetIgnoreMissingKeyForTesting(true); TranslateManager::SetIgnoreMissingKeyForTesting(true);
ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
InProcessBrowserTest::SetUp(); InProcessBrowserTest::SetUp();
} }
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(
switches::kTranslateScriptURL,
embedded_test_server()->GetURL("/mock_translate_script.js").spec());
}
void SetUpOnMainThread() override {
embedded_test_server()->StartAcceptingConnections();
}
void TearDownOnMainThread() override {
EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
InProcessBrowserTest::TearDownOnMainThread();
}
protected: protected:
void NavigateAndWaitForLanguageDetection(const GURL& url, void NavigateAndWaitForLanguageDetection(const GURL& url,
const std::string& expected_lang) { const std::string& expected_lang) {
...@@ -69,8 +86,7 @@ IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, ...@@ -69,8 +86,7 @@ IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest,
EXPECT_FALSE(TranslateBubbleView::GetCurrentBubble()); EXPECT_FALSE(TranslateBubbleView::GetCurrentBubble());
// Show a French page and wait until the bubble is shown. // Show a French page and wait until the bubble is shown.
GURL french_url = ui_test_utils::GetTestUrl( GURL french_url = GURL(embedded_test_server()->GetURL("/french_page.html"));
base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html")));
NavigateAndWaitForLanguageDetection(french_url, "fr"); NavigateAndWaitForLanguageDetection(french_url, "fr");
EXPECT_TRUE(TranslateBubbleView::GetCurrentBubble()); EXPECT_TRUE(TranslateBubbleView::GetCurrentBubble());
...@@ -86,8 +102,7 @@ IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, ...@@ -86,8 +102,7 @@ IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest,
EXPECT_FALSE(TranslateBubbleView::GetCurrentBubble()); EXPECT_FALSE(TranslateBubbleView::GetCurrentBubble());
// Show a French page and wait until the bubble is shown. // Show a French page and wait until the bubble is shown.
GURL french_url = ui_test_utils::GetTestUrl( GURL french_url = GURL(embedded_test_server()->GetURL("/french_page.html"));
base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html")));
NavigateAndWaitForLanguageDetection(french_url, "fr"); NavigateAndWaitForLanguageDetection(french_url, "fr");
EXPECT_TRUE(TranslateBubbleView::GetCurrentBubble()); EXPECT_TRUE(TranslateBubbleView::GetCurrentBubble());
...@@ -108,8 +123,7 @@ IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, ...@@ -108,8 +123,7 @@ IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest,
// Open another tab to load a French page on background. // Open another tab to load a French page on background.
int french_index = active_index + 1; int french_index = active_index + 1;
GURL french_url = ui_test_utils::GetTestUrl( GURL french_url = GURL(embedded_test_server()->GetURL("/french_page.html"));
base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html")));
chrome::AddTabAt(browser(), french_url, french_index, false); chrome::AddTabAt(browser(), french_url, french_index, false);
EXPECT_EQ(active_index, browser()->tab_strip_model()->active_index()); EXPECT_EQ(active_index, browser()->tab_strip_model()->active_index());
EXPECT_EQ(2, browser()->tab_strip_model()->count()); EXPECT_EQ(2, browser()->tab_strip_model()->count());
...@@ -136,8 +150,7 @@ IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, AlertAccessibleEvent) { ...@@ -136,8 +150,7 @@ IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, AlertAccessibleEvent) {
views::test::AXEventCounter counter(views::AXEventManager::Get()); views::test::AXEventCounter counter(views::AXEventManager::Get());
EXPECT_EQ(0, counter.GetCount(ax::mojom::Event::kAlert)); EXPECT_EQ(0, counter.GetCount(ax::mojom::Event::kAlert));
GURL french_url = ui_test_utils::GetTestUrl( GURL french_url = GURL(embedded_test_server()->GetURL("/french_page.html"));
base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html")));
NavigateAndWaitForLanguageDetection(french_url, "fr"); NavigateAndWaitForLanguageDetection(french_url, "fr");
// TODO(crbug.com/1082217): This should produce one event instead of two. // TODO(crbug.com/1082217): This should produce one event instead of two.
......
...@@ -40,14 +40,10 @@ namespace translate { ...@@ -40,14 +40,10 @@ namespace translate {
namespace { namespace {
const base::FilePath::CharType kEnglishTestPath[] = const char kEnglishTestPath[] = "/english_page.html";
FILE_PATH_LITERAL("english_page.html"); const char kItalianTestPath[] = "/italian_page.html";
const base::FilePath::CharType kItalianTestPath[] = const char kFrenchTestPath[] = "/french_page.html";
FILE_PATH_LITERAL("italian_page.html"); const char kGermanTestPath[] = "/german_page.html";
const base::FilePath::CharType kFrenchTestPath[] =
FILE_PATH_LITERAL("french_page.html");
const base::FilePath::CharType kGermanTestPath[] =
FILE_PATH_LITERAL("german_page.html");
static const char kTestValidScript[] = static const char kTestValidScript[] =
"var google = {};" "var google = {};"
...@@ -115,7 +111,7 @@ class TranslateLanguageBrowserTest : public InProcessBrowserTest { ...@@ -115,7 +111,7 @@ class TranslateLanguageBrowserTest : public InProcessBrowserTest {
browser_ = incognito ? CreateIncognitoBrowser() : browser(); browser_ = incognito ? CreateIncognitoBrowser() : browser();
} }
void NavigateToUrl(const base::FilePath::StringPieceType path) { void NavigateToUrl(const char* path) {
// Close previous Translate bubble, if it exists. This is intended to // Close previous Translate bubble, if it exists. This is intended to
// prevent a race condition in which the previous page's call to // prevent a race condition in which the previous page's call to
// TranslateBubbleView::WindowClosing doesn't occur until after the new page // TranslateBubbleView::WindowClosing doesn't occur until after the new page
...@@ -124,13 +120,11 @@ class TranslateLanguageBrowserTest : public InProcessBrowserTest { ...@@ -124,13 +120,11 @@ class TranslateLanguageBrowserTest : public InProcessBrowserTest {
// TODO(789593): investigate a more robust fix. // TODO(789593): investigate a more robust fix.
TranslateBubbleView::CloseCurrentBubble(); TranslateBubbleView::CloseCurrentBubble();
const GURL url = ui_test_utils::NavigateToURL(browser_,
ui_test_utils::GetTestUrl(base::FilePath(), base::FilePath(path)); GURL(embedded_test_server()->GetURL(path)));
ui_test_utils::NavigateToURL(browser_, url);
} }
void CheckForTranslateUI(const base::FilePath::StringPieceType path, void CheckForTranslateUI(const char* path, const bool expect_translate) {
const bool expect_translate) {
ASSERT_TRUE(browser_); ASSERT_TRUE(browser_);
auto waiter = CreateTranslateWaiter( auto waiter = CreateTranslateWaiter(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment