Commit 0fdb4980 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Make SyncInternalsMessageHandlerTest a ChromeRenderViewHostTestHarness.

This simplifies the test and allows it to pass in single process mash
due to extra setup in the test fixture.

(Technically, it also passes 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: Ib85c034c9e83d9c6fbcbcece130401e37621609e
Reviewed-on: https://chromium-review.googlesource.com/c/1343283
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarTim Schumann <tschumann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610952}
parent 5f2ddba6
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/user_event_service_factory.h" #include "chrome/browser/sync/user_event_service_factory.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 "components/browser_sync/browser_sync_switches.h" #include "components/browser_sync/browser_sync_switches.h"
#include "components/sync/driver/about_sync_util.h" #include "components/sync/driver/about_sync_util.h"
...@@ -21,9 +21,7 @@ ...@@ -21,9 +21,7 @@
#include "components/sync/user_events/fake_user_event_service.h" #include "components/sync/user_events/fake_user_event_service.h"
#include "content/public/browser/site_instance.h" #include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_web_ui.h" #include "content/public/test/test_web_ui.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::DictionaryValue; using base::DictionaryValue;
using base::ListValue; using base::ListValue;
...@@ -106,20 +104,22 @@ static std::unique_ptr<KeyedService> BuildFakeUserEventService( ...@@ -106,20 +104,22 @@ static std::unique_ptr<KeyedService> BuildFakeUserEventService(
return std::make_unique<FakeUserEventService>(); return std::make_unique<FakeUserEventService>();
} }
class SyncInternalsMessageHandlerTest : public ::testing::Test { class SyncInternalsMessageHandlerTest : public ChromeRenderViewHostTestHarness {
protected: protected:
SyncInternalsMessageHandlerTest() { SyncInternalsMessageHandlerTest() = default;
site_instance_ = content::SiteInstance::Create(&profile_); ~SyncInternalsMessageHandlerTest() override = default;
web_contents_ = content::WebContents::Create(
content::WebContents::CreateParams(&profile_, site_instance_.get())); void SetUp() override {
web_ui_.set_web_contents(web_contents_.get()); ChromeRenderViewHostTestHarness::SetUp();
web_ui_.set_web_contents(web_contents());
test_sync_service_ = static_cast<TestSyncService*>( test_sync_service_ = static_cast<TestSyncService*>(
ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
&profile_, base::BindRepeating(&BuildTestSyncService))); profile(), base::BindRepeating(&BuildTestSyncService)));
fake_user_event_service_ = static_cast<FakeUserEventService*>( fake_user_event_service_ = static_cast<FakeUserEventService*>(
browser_sync::UserEventServiceFactory::GetInstance() browser_sync::UserEventServiceFactory::GetInstance()
->SetTestingFactoryAndUse( ->SetTestingFactoryAndUse(
&profile_, base::BindRepeating(&BuildFakeUserEventService))); profile(), base::BindRepeating(&BuildFakeUserEventService)));
handler_.reset(new TestableSyncInternalsMessageHandler( handler_.reset(new TestableSyncInternalsMessageHandler(
&web_ui_, &web_ui_,
base::BindRepeating( base::BindRepeating(
...@@ -127,6 +127,12 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test { ...@@ -127,6 +127,12 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test {
base::Unretained(this)))); base::Unretained(this))));
} }
void TearDown() override {
// Destroy |handler_| before |web_contents()|.
handler_ = nullptr;
ChromeRenderViewHostTestHarness::TearDown();
}
std::unique_ptr<DictionaryValue> ConstructAboutInformation( std::unique_ptr<DictionaryValue> ConstructAboutInformation(
SyncService* service, SyncService* service,
version_info::Channel channel) { version_info::Channel channel) {
...@@ -167,8 +173,6 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test { ...@@ -167,8 +173,6 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test {
EXPECT_TRUE(web_ui_.call_data().empty()); EXPECT_TRUE(web_ui_.call_data().empty());
} }
TestingProfile* profile() { return &profile_; }
TestSyncService* test_sync_service() { return test_sync_service_; } TestSyncService* test_sync_service() { return test_sync_service_; }
FakeUserEventService* fake_user_event_service() { FakeUserEventService* fake_user_event_service() {
...@@ -198,16 +202,14 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test { ...@@ -198,16 +202,14 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test {
void ResetHandler() { handler_.reset(); } void ResetHandler() { handler_.reset(); }
private: private:
content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
scoped_refptr<content::SiteInstance> site_instance_;
std::unique_ptr<content::WebContents> web_contents_;
content::TestWebUI web_ui_; content::TestWebUI web_ui_;
TestSyncService* test_sync_service_; TestSyncService* test_sync_service_;
FakeUserEventService* fake_user_event_service_; FakeUserEventService* fake_user_event_service_;
std::unique_ptr<TestableSyncInternalsMessageHandler> handler_; std::unique_ptr<TestableSyncInternalsMessageHandler> handler_;
int about_sync_data_delegate_call_count_ = 0; int about_sync_data_delegate_call_count_ = 0;
SyncService* last_delegate_sync_service_ = nullptr; SyncService* last_delegate_sync_service_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandlerTest);
}; };
TEST_F(SyncInternalsMessageHandlerTest, AddRemoveObservers) { TEST_F(SyncInternalsMessageHandlerTest, AddRemoveObservers) {
......
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