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