Commit e96029c3 authored by Kevin McNee's avatar Kevin McNee Committed by Commit Bot

Address potentially racy uses of ExtensionTestMessageListener in ExtensionWebUITests

We now have all listeners created before performing the action that will
lead to the expected message being sent.

Bug: None
Change-Id: I7b300136dedee619842d4753cd6d291fd8205b4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954807Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Kevin McNee <mcnee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722584}
parent 5c2142a0
...@@ -138,17 +138,16 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckUnavailableAPIs) { ...@@ -138,17 +138,16 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SanityCheckUnavailableAPIs) {
// Tests chrome.test.sendMessage, which exercises WebUI making a // Tests chrome.test.sendMessage, which exercises WebUI making a
// function call and receiving a response. // function call and receiving a response.
IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SendMessage) { IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SendMessage) {
std::unique_ptr<ExtensionTestMessageListener> listener( ExtensionTestMessageListener ping_listener("ping", true);
new ExtensionTestMessageListener("ping", true));
ASSERT_TRUE(RunTestOnExtensionsPage("send_message.js")); ASSERT_TRUE(RunTestOnExtensionsPage("send_message.js"));
ASSERT_TRUE(ping_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied()); ExtensionTestMessageListener result_listener(false);
listener->Reply("pong"); ping_listener.Reply("pong");
listener.reset(new ExtensionTestMessageListener(false)); ASSERT_TRUE(result_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied()); EXPECT_EQ("true", result_listener.message());
EXPECT_EQ("true", listener->message());
} }
// Tests chrome.runtime.onMessage, which exercises WebUI registering and // Tests chrome.runtime.onMessage, which exercises WebUI registering and
...@@ -156,6 +155,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SendMessage) { ...@@ -156,6 +155,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, SendMessage) {
IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, OnMessage) { IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, OnMessage) {
ASSERT_TRUE(RunTestOnExtensionsPage("on_message.js")); ASSERT_TRUE(RunTestOnExtensionsPage("on_message.js"));
ExtensionTestMessageListener result_listener(false);
OnMessage::Info info; OnMessage::Info info;
info.data = "hi"; info.data = "hi";
info.last_message = true; info.last_message = true;
...@@ -163,31 +164,26 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, OnMessage) { ...@@ -163,31 +164,26 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, OnMessage) {
new Event(events::RUNTIME_ON_MESSAGE, OnMessage::kEventName, new Event(events::RUNTIME_ON_MESSAGE, OnMessage::kEventName,
OnMessage::Create(info)))); OnMessage::Create(info))));
std::unique_ptr<ExtensionTestMessageListener> listener( ASSERT_TRUE(result_listener.WaitUntilSatisfied());
new ExtensionTestMessageListener(false)); EXPECT_EQ("true", result_listener.message());
ASSERT_TRUE(listener->WaitUntilSatisfied());
EXPECT_EQ("true", listener->message());
} }
// Tests chrome.runtime.lastError, which exercises WebUI accessing a property // Tests chrome.runtime.lastError, which exercises WebUI accessing a property
// on an API which it doesn't actually have access to. A bindings test really. // on an API which it doesn't actually have access to. A bindings test really.
IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, RuntimeLastError) { IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, RuntimeLastError) {
std::unique_ptr<ExtensionTestMessageListener> listener( ExtensionTestMessageListener ping_listener("ping", true);
new ExtensionTestMessageListener("ping", true));
ASSERT_TRUE(RunTestOnExtensionsPage("runtime_last_error.js")); ASSERT_TRUE(RunTestOnExtensionsPage("runtime_last_error.js"));
ASSERT_TRUE(ping_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied()); ExtensionTestMessageListener result_listener(false);
listener->ReplyWithError("unknown host"); ping_listener.ReplyWithError("unknown host");
ASSERT_TRUE(result_listener.WaitUntilSatisfied());
listener.reset(new ExtensionTestMessageListener(false)); EXPECT_EQ("true", result_listener.message());
ASSERT_TRUE(listener->WaitUntilSatisfied());
EXPECT_EQ("true", listener->message());
} }
IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) { IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) {
std::unique_ptr<ExtensionTestMessageListener> listener( ExtensionTestMessageListener ready_listener("ready", true);
new ExtensionTestMessageListener("ready", true));
const Extension* extension = const Extension* extension =
LoadExtension(test_data_dir_.AppendASCII("extension_options") LoadExtension(test_data_dir_.AppendASCII("extension_options")
...@@ -195,11 +191,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) { ...@@ -195,11 +191,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) {
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
ASSERT_TRUE(RunTestOnExtensionsPage("can_embed_extension_options.js")); ASSERT_TRUE(RunTestOnExtensionsPage("can_embed_extension_options.js"));
ASSERT_TRUE(ready_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied()); ExtensionTestMessageListener load_listener("load", false);
listener->Reply(extension->id()); ready_listener.Reply(extension->id());
listener.reset(new ExtensionTestMessageListener("load", false)); ASSERT_TRUE(load_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied());
} }
// Tests that an <extensionoptions> guest view can access the chrome.storage // Tests that an <extensionoptions> guest view can access the chrome.storage
...@@ -290,8 +286,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUIEmbeddedOptionsTest, ...@@ -290,8 +286,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUIEmbeddedOptionsTest,
} }
IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, ReceivesExtensionOptionsOnClose) { IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, ReceivesExtensionOptionsOnClose) {
std::unique_ptr<ExtensionTestMessageListener> listener( ExtensionTestMessageListener ready_listener("ready", true);
new ExtensionTestMessageListener("ready", true));
const Extension* extension = const Extension* extension =
InstallExtension(test_data_dir_.AppendASCII("extension_options") InstallExtension(test_data_dir_.AppendASCII("extension_options")
...@@ -300,11 +295,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, ReceivesExtensionOptionsOnClose) { ...@@ -300,11 +295,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, ReceivesExtensionOptionsOnClose) {
ASSERT_TRUE( ASSERT_TRUE(
RunTestOnExtensionsPage("receives_extension_options_on_close.js")); RunTestOnExtensionsPage("receives_extension_options_on_close.js"));
ASSERT_TRUE(ready_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied()); ExtensionTestMessageListener onclose_listener("onclose received", false);
listener->Reply(extension->id()); ready_listener.Reply(extension->id());
listener.reset(new ExtensionTestMessageListener("onclose received", false)); ASSERT_TRUE(onclose_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied());
} }
// Regression test for crbug.com/414526. // Regression test for crbug.com/414526.
...@@ -312,8 +307,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, ReceivesExtensionOptionsOnClose) { ...@@ -312,8 +307,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, ReceivesExtensionOptionsOnClose) {
// Same setup as CanEmbedExtensionOptions but disable the extension before // Same setup as CanEmbedExtensionOptions but disable the extension before
// embedding. // embedding.
IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, EmbedDisabledExtension) { IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, EmbedDisabledExtension) {
std::unique_ptr<ExtensionTestMessageListener> listener( ExtensionTestMessageListener ready_listener("ready", true);
new ExtensionTestMessageListener("ready", true));
std::string extension_id; std::string extension_id;
{ {
...@@ -326,11 +320,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, EmbedDisabledExtension) { ...@@ -326,11 +320,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, EmbedDisabledExtension) {
} }
ASSERT_TRUE(RunTestOnExtensionsPage("can_embed_extension_options.js")); ASSERT_TRUE(RunTestOnExtensionsPage("can_embed_extension_options.js"));
ASSERT_TRUE(ready_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied()); ExtensionTestMessageListener create_failed_listener("createfailed", false);
listener->Reply(extension_id); ready_listener.Reply(extension_id);
listener.reset(new ExtensionTestMessageListener("createfailed", false)); ASSERT_TRUE(create_failed_listener.WaitUntilSatisfied());
ASSERT_TRUE(listener->WaitUntilSatisfied());
} }
IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, EmbedInvalidExtension) { IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, EmbedInvalidExtension) {
......
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