Commit ae562a2d authored by Katie Dektar's avatar Katie Dektar Committed by Chromium LUCI CQ

Improve STS integration test by catching console errors and warnings.

This will let us do things similar to DCHECK for test by logging any
bad state in the extension and causing a test failure. It also serves to
remind developers to remove verbose logging.

AX-Relnotes: N/A
Bug: N/A
Change-Id: I1011b8818d3e77da2a3bc08fe2f8da1158ffbdab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2633366Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844239}
parent c191289b
...@@ -69,12 +69,34 @@ class SelectToSpeakTest : public InProcessBrowserTest { ...@@ -69,12 +69,34 @@ class SelectToSpeakTest : public InProcessBrowserTest {
AccessibilityManager::Get()->SetSelectToSpeakEnabled(true); AccessibilityManager::Get()->SetSelectToSpeakEnabled(true);
extension_load_waiter.Wait(); extension_load_waiter.Wait();
extensions::ExtensionHost* host =
extensions::ProcessManager::Get(browser()->profile())
->GetBackgroundHostForExtension(
extension_misc::kSelectToSpeakExtensionId);
console_observer_ = std::make_unique<content::WebContentsConsoleObserver>(
host->host_contents());
// STS should not log warnings or errors: these should cause test failures.
auto filter =
[](const content::WebContentsConsoleObserver::Message& message) {
return message.log_level ==
blink::mojom::ConsoleMessageLevel::kWarning ||
message.log_level == blink::mojom::ConsoleMessageLevel::kError;
};
console_observer_->SetFilter(base::BindRepeating(filter));
aura::Window* root_window = ash::Shell::Get()->GetPrimaryRootWindow(); aura::Window* root_window = ash::Shell::Get()->GetPrimaryRootWindow();
generator_.reset(new ui::test::EventGenerator(root_window)); generator_.reset(new ui::test::EventGenerator(root_window));
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
} }
void TearDownOnMainThread() override {
// Check STS has not generated any errors.
EXPECT_EQ(0, console_observer_->messages().size())
<< "Found console.log or console.warn with message: "
<< console_observer_->GetMessageAt(0);
}
test::SpeechMonitor sm_; test::SpeechMonitor sm_;
std::unique_ptr<ui::test::EventGenerator> generator_; std::unique_ptr<ui::test::EventGenerator> generator_;
std::unique_ptr<ash::SystemTrayTestApi> tray_test_api_; std::unique_ptr<ash::SystemTrayTestApi> tray_test_api_;
...@@ -149,6 +171,7 @@ class SelectToSpeakTest : public InProcessBrowserTest { ...@@ -149,6 +171,7 @@ class SelectToSpeakTest : public InProcessBrowserTest {
private: private:
scoped_refptr<content::MessageLoopRunner> loop_runner_; scoped_refptr<content::MessageLoopRunner> loop_runner_;
scoped_refptr<content::MessageLoopRunner> tray_loop_runner_; scoped_refptr<content::MessageLoopRunner> tray_loop_runner_;
std::unique_ptr<content::WebContentsConsoleObserver> console_observer_;
base::WeakPtrFactory<SelectToSpeakTest> weak_ptr_factory_{this}; base::WeakPtrFactory<SelectToSpeakTest> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(SelectToSpeakTest); DISALLOW_COPY_AND_ASSIGN(SelectToSpeakTest);
}; };
......
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