Commit 1e3605ec authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

chromeos: Prepare browsertests for PostTask refactor

This delays initialization of MockMediaRouters in chromeos tests until
the browser's task executor is initialized.

This is required for the upcoming move of
BrowserThread::GetTaskRunnerForThread to
base::Create*TaskRunnerWithTraits. In the future, TaskRunners can only
be obtained after thread initialization. Since MockMediaRouter obtains
a TaskRunner in its constructor, this patch moves its creation.

TBR=mtomasz@chromium.org,dominickn@chromium.org

Bug: 878356
Change-Id: I951e02617de4b81dabe8ed16b8d760028fa6547f
Reviewed-on: https://chromium-review.googlesource.com/1230038Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591999}
parent 5a0a4475
......@@ -49,6 +49,8 @@ PlatformAppBrowserTest::PlatformAppBrowserTest() {
ChromeAppDelegate::DisableExternalOpenForTesting();
}
PlatformAppBrowserTest::~PlatformAppBrowserTest() {}
void PlatformAppBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
// Skips ExtensionApiTest::SetUpCommandLine.
ExtensionBrowserTest::SetUpCommandLine(command_line);
......@@ -58,25 +60,26 @@ void PlatformAppBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
ProcessManager::SetEventPageSuspendingTimeForTesting(1000);
}
void PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture() {
ExtensionApiTest::SetUpInProcessBrowserTestFixture();
void PlatformAppBrowserTest::SetUpOnMainThread() {
ExtensionApiTest::SetUpOnMainThread();
#if defined(OS_CHROMEOS)
// Mock the Media Router in extension api tests. Several of the
// PlatformAppBrowserTest suites call RunAllPendingInMessageLoop() when there
// are mojo messages that will call back into Profile creation through the
// media router.
ON_CALL(media_router_, RegisterMediaSinksObserver(testing::_))
media_router_ = std::make_unique<media_router::MockMediaRouter>();
ON_CALL(*media_router_, RegisterMediaSinksObserver(testing::_))
.WillByDefault(testing::Return(true));
CastConfigClientMediaRouter::SetMediaRouterForTest(&media_router_);
CastConfigClientMediaRouter::SetMediaRouterForTest(media_router_.get());
#endif
}
void PlatformAppBrowserTest::TearDownInProcessBrowserTestFixture() {
void PlatformAppBrowserTest::TearDownOnMainThread() {
#if defined(OS_CHROMEOS)
CastConfigClientMediaRouter::SetMediaRouterForTest(nullptr);
#endif
ExtensionApiTest::TearDownInProcessBrowserTestFixture();
ExtensionApiTest::TearDownOnMainThread();
}
// static
......
......@@ -7,6 +7,7 @@
#include <stddef.h>
#include <memory>
#include <string>
#include "base/macros.h"
......@@ -35,10 +36,11 @@ class Extension;
class PlatformAppBrowserTest : public ExtensionApiTest {
public:
PlatformAppBrowserTest();
~PlatformAppBrowserTest() override;
void SetUpCommandLine(base::CommandLine* command_line) override;
void SetUpInProcessBrowserTestFixture() override;
void TearDownInProcessBrowserTestFixture() override;
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
// Gets the first app window that is found for a given browser.
static AppWindow* GetFirstAppWindowForBrowser(Browser* browser);
......@@ -129,7 +131,7 @@ class PlatformAppBrowserTest : public ExtensionApiTest {
private:
#if defined(OS_CHROMEOS)
media_router::MockMediaRouter media_router_;
std::unique_ptr<media_router::MockMediaRouter> media_router_;
#endif
DISALLOW_COPY_AND_ASSIGN(PlatformAppBrowserTest);
......
......@@ -294,9 +294,10 @@ class FileSystemExtensionApiTestBase : public extensions::ExtensionApiTest {
// Mock the Media Router in extension api tests. Dispatches to the message
// loop now try to handle mojo messages that will call back into Profile
// creation through the media router, which then confuse the drive code.
ON_CALL(media_router_, RegisterMediaSinksObserver(testing::_))
media_router_ = std::make_unique<media_router::MockMediaRouter>();
ON_CALL(*media_router_, RegisterMediaSinksObserver(testing::_))
.WillByDefault(testing::Return(true));
CastConfigClientMediaRouter::SetMediaRouterForTest(&media_router_);
CastConfigClientMediaRouter::SetMediaRouterForTest(media_router_.get());
extensions::ExtensionApiTest::SetUpOnMainThread();
}
......@@ -370,7 +371,7 @@ class FileSystemExtensionApiTestBase : public extensions::ExtensionApiTest {
virtual void AddTestMountPoint() = 0;
private:
media_router::MockMediaRouter media_router_;
std::unique_ptr<media_router::MockMediaRouter> media_router_;
DISALLOW_COPY_AND_ASSIGN(FileSystemExtensionApiTestBase);
};
......
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