Commit 169bc3fe authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Make SyncSessionsWebContentsRouterTest a ChromeRenderViewHostTestHarness

This simplifies the test fixture and allows the tests to pass in
single process mash.

(Technically, they also pass in single process mash without this change,
but would cease to do so after AuraTestSuite stops creating an
InputDeviceClient, which will soon happen.)

Bug: 905430
Change-Id: I9536989b016176b96db824732720b86d6442f27d
Reviewed-on: https://chromium-review.googlesource.com/c/1343338
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609776}
parent 893d53ce
...@@ -7,10 +7,8 @@ ...@@ -7,10 +7,8 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/sync/sessions/sync_sessions_web_contents_router_factory.h" #include "chrome/browser/sync/sessions/sync_sessions_web_contents_router_factory.h"
#include "chrome/browser/ui/sync/browser_synced_tab_delegate.h" #include "chrome/browser/ui/sync/browser_synced_tab_delegate.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sync_sessions { namespace sync_sessions {
...@@ -27,26 +25,25 @@ class StartSyncFlareMock { ...@@ -27,26 +25,25 @@ class StartSyncFlareMock {
bool was_run_ = false; bool was_run_ = false;
}; };
class SyncSessionsWebContentsRouterTest : public testing::Test { class SyncSessionsWebContentsRouterTest
: public ChromeRenderViewHostTestHarness {
protected: protected:
~SyncSessionsWebContentsRouterTest() override {} SyncSessionsWebContentsRouterTest() = default;
~SyncSessionsWebContentsRouterTest() override = default;
void SetUp() override { void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
router_ = router_ =
SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile( SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile(
&profile_); profile());
test_contents_ =
content::WebContentsTester::CreateTestWebContents(&profile_, nullptr);
} }
SyncSessionsWebContentsRouter* router() { return router_; } SyncSessionsWebContentsRouter* router() { return router_; }
content::WebContents* test_contents() { return test_contents_.get(); }
private: private:
content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
SyncSessionsWebContentsRouter* router_; SyncSessionsWebContentsRouter* router_;
std::unique_ptr<content::WebContents> test_contents_;
DISALLOW_COPY_AND_ASSIGN(SyncSessionsWebContentsRouterTest);
}; };
// Disabled on android due to complexity of creating a full TabAndroid object // Disabled on android due to complexity of creating a full TabAndroid object
...@@ -59,25 +56,25 @@ TEST_F(SyncSessionsWebContentsRouterTest, FlareNotRun) { ...@@ -59,25 +56,25 @@ TEST_F(SyncSessionsWebContentsRouterTest, FlareNotRun) {
base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock))); base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock)));
// There's no delegate for the tab, so the flare shouldn't run. // There's no delegate for the tab, so the flare shouldn't run.
router()->NotifyTabModified(test_contents(), false); router()->NotifyTabModified(web_contents(), false);
EXPECT_FALSE(mock.was_run()); EXPECT_FALSE(mock.was_run());
BrowserSyncedTabDelegate::CreateForWebContents(test_contents()); BrowserSyncedTabDelegate::CreateForWebContents(web_contents());
// There's a delegate for the tab, but it's not a load completed event, so the // There's a delegate for the tab, but it's not a load completed event, so the
// flare still shouldn't run. // flare still shouldn't run.
router()->NotifyTabModified(test_contents(), false); router()->NotifyTabModified(web_contents(), false);
EXPECT_FALSE(mock.was_run()); EXPECT_FALSE(mock.was_run());
} }
// Make sure we don't crash when there's not a flare. // Make sure we don't crash when there's not a flare.
TEST_F(SyncSessionsWebContentsRouterTest, FlareNotSet) { TEST_F(SyncSessionsWebContentsRouterTest, FlareNotSet) {
BrowserSyncedTabDelegate::CreateForWebContents(test_contents()); BrowserSyncedTabDelegate::CreateForWebContents(web_contents());
router()->NotifyTabModified(test_contents(), false); router()->NotifyTabModified(web_contents(), false);
} }
TEST_F(SyncSessionsWebContentsRouterTest, FlareRunsForLoadCompleted) { TEST_F(SyncSessionsWebContentsRouterTest, FlareRunsForLoadCompleted) {
BrowserSyncedTabDelegate::CreateForWebContents(test_contents()); BrowserSyncedTabDelegate::CreateForWebContents(web_contents());
StartSyncFlareMock mock; StartSyncFlareMock mock;
router()->InjectStartSyncFlare( router()->InjectStartSyncFlare(
...@@ -85,7 +82,7 @@ TEST_F(SyncSessionsWebContentsRouterTest, FlareRunsForLoadCompleted) { ...@@ -85,7 +82,7 @@ TEST_F(SyncSessionsWebContentsRouterTest, FlareRunsForLoadCompleted) {
// There's a delegate for the tab, and it's a load completed event, so the // There's a delegate for the tab, and it's a load completed event, so the
// flare should run. // flare should run.
router()->NotifyTabModified(test_contents(), true); router()->NotifyTabModified(web_contents(), true);
EXPECT_TRUE(mock.was_run()); EXPECT_TRUE(mock.was_run());
} }
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
......
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