Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: chrome/browser/ui/webui/sync_internals_message_handler_unittest.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/sync_internals_message_handler.h" 5 #include "chrome/browser/ui/webui/sync_internals_message_handler.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "components/browser_sync/common/browser_sync_switches.h" 13 #include "components/browser_sync/common/browser_sync_switches.h"
14 #include "components/sync_driver/about_sync_util.h" 14 #include "components/sync_driver/about_sync_util.h"
15 #include "components/sync_driver/sync_service.h" 15 #include "components/sync_driver/sync_service.h"
16 #include "content/public/browser/site_instance.h" 16 #include "content/public/browser/site_instance.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "content/public/test/test_web_ui.h" 19 #include "content/public/test/test_web_ui.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace { 22 namespace {
23 23
24 class TestableSyncInternalsMessageHandler : public SyncInternalsMessageHandler { 24 class TestableSyncInternalsMessageHandler : public SyncInternalsMessageHandler {
25 public: 25 public:
26 explicit TestableSyncInternalsMessageHandler( 26 explicit TestableSyncInternalsMessageHandler(
27 content::WebUI* web_ui, 27 content::WebUI* web_ui,
28 scoped_ptr<AboutSyncDataExtractor> about_sync_data_extractor) 28 std::unique_ptr<AboutSyncDataExtractor> about_sync_data_extractor)
29 : SyncInternalsMessageHandler(std::move(about_sync_data_extractor)) { 29 : SyncInternalsMessageHandler(std::move(about_sync_data_extractor)) {
30 set_web_ui(web_ui); 30 set_web_ui(web_ui);
31 } 31 }
32 }; 32 };
33 33
34 class FakeExtractor : public AboutSyncDataExtractor { 34 class FakeExtractor : public AboutSyncDataExtractor {
35 public: 35 public:
36 scoped_ptr<base::DictionaryValue> ConstructAboutInformation( 36 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
37 sync_driver::SyncService* service, 37 sync_driver::SyncService* service,
38 SigninManagerBase* signin) override { 38 SigninManagerBase* signin) override {
39 call_count_++; 39 call_count_++;
40 last_service_ = service; 40 last_service_ = service;
41 last_signin_ = signin; 41 last_signin_ = signin;
42 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); 42 std::unique_ptr<base::DictionaryValue> dictionary(
43 new base::DictionaryValue());
43 dictionary->SetString("fake_key", "fake_value"); 44 dictionary->SetString("fake_key", "fake_value");
44 return dictionary; 45 return dictionary;
45 } 46 }
46 47
47 int call_count() const { return call_count_; } 48 int call_count() const { return call_count_; }
48 sync_driver::SyncService* last_service() const { return last_service_; } 49 sync_driver::SyncService* last_service() const { return last_service_; }
49 SigninManagerBase* last_signin() const { return last_signin_; } 50 SigninManagerBase* last_signin() const { return last_signin_; }
50 51
51 private: 52 private:
52 int call_count_ = 0; 53 int call_count_ = 0;
53 sync_driver::SyncService* last_service_ = nullptr; 54 sync_driver::SyncService* last_service_ = nullptr;
54 SigninManagerBase* last_signin_ = nullptr; 55 SigninManagerBase* last_signin_ = nullptr;
55 }; 56 };
56 57
57 class SyncInternalsMessageHandlerTest : public ::testing::Test { 58 class SyncInternalsMessageHandlerTest : public ::testing::Test {
58 protected: 59 protected:
59 SyncInternalsMessageHandlerTest() { 60 SyncInternalsMessageHandlerTest() {
60 site_instance_ = content::SiteInstance::Create(&profile_); 61 site_instance_ = content::SiteInstance::Create(&profile_);
61 web_contents_.reset(content::WebContents::Create( 62 web_contents_.reset(content::WebContents::Create(
62 content::WebContents::CreateParams(&profile_, site_instance_.get()))); 63 content::WebContents::CreateParams(&profile_, site_instance_.get())));
63 web_ui_.set_web_contents(web_contents_.get()); 64 web_ui_.set_web_contents(web_contents_.get());
64 fake_extractor_ = new FakeExtractor(); 65 fake_extractor_ = new FakeExtractor();
65 handler_.reset(new TestableSyncInternalsMessageHandler( 66 handler_.reset(new TestableSyncInternalsMessageHandler(
66 &web_ui_, scoped_ptr<FakeExtractor>(fake_extractor_))); 67 &web_ui_, std::unique_ptr<FakeExtractor>(fake_extractor_)));
67 } 68 }
68 69
69 void ValidateAboutInfoCall() { 70 void ValidateAboutInfoCall() {
70 const ScopedVector<content::TestWebUI::CallData>& data_vector = 71 const ScopedVector<content::TestWebUI::CallData>& data_vector =
71 web_ui_.call_data(); 72 web_ui_.call_data();
72 ASSERT_FALSE(data_vector.empty()); 73 ASSERT_FALSE(data_vector.empty());
73 EXPECT_EQ(1u, data_vector.size()); 74 EXPECT_EQ(1u, data_vector.size());
74 75
75 const content::TestWebUI::CallData& call_data = *data_vector[0]; 76 const content::TestWebUI::CallData& call_data = *data_vector[0];
76 77
(...skipping 18 matching lines...) Expand all
95 } 96 }
96 97
97 SyncInternalsMessageHandler* handler() { return handler_.get(); } 98 SyncInternalsMessageHandler* handler() { return handler_.get(); }
98 FakeExtractor* fake_extractor() { return fake_extractor_; } 99 FakeExtractor* fake_extractor() { return fake_extractor_; }
99 100
100 private: 101 private:
101 content::TestBrowserThreadBundle thread_bundle_; 102 content::TestBrowserThreadBundle thread_bundle_;
102 TestingProfile profile_; 103 TestingProfile profile_;
103 content::TestWebUI web_ui_; 104 content::TestWebUI web_ui_;
104 scoped_refptr<content::SiteInstance> site_instance_; 105 scoped_refptr<content::SiteInstance> site_instance_;
105 scoped_ptr<content::WebContents> web_contents_; 106 std::unique_ptr<content::WebContents> web_contents_;
106 scoped_ptr<SyncInternalsMessageHandler> handler_; 107 std::unique_ptr<SyncInternalsMessageHandler> handler_;
107 108
108 // Non-owning pointer to the about information the handler uses. This 109 // Non-owning pointer to the about information the handler uses. This
109 // extractor is owned by the handler. 110 // extractor is owned by the handler.
110 FakeExtractor* fake_extractor_; 111 FakeExtractor* fake_extractor_;
111 }; 112 };
112 113
113 } // namespace 114 } // namespace
114 115
115 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithService) { 116 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithService) {
116 handler()->OnStateChanged(); 117 handler()->OnStateChanged();
117 EXPECT_EQ(1, fake_extractor()->call_count()); 118 EXPECT_EQ(1, fake_extractor()->call_count());
118 EXPECT_NE(nullptr, fake_extractor()->last_service()); 119 EXPECT_NE(nullptr, fake_extractor()->last_service());
119 EXPECT_NE(nullptr, fake_extractor()->last_signin()); 120 EXPECT_NE(nullptr, fake_extractor()->last_signin());
120 ValidateAboutInfoCall(); 121 ValidateAboutInfoCall();
121 } 122 }
122 123
123 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithoutService) { 124 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithoutService) {
124 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); 125 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync);
125 handler()->OnStateChanged(); 126 handler()->OnStateChanged();
126 EXPECT_EQ(1, fake_extractor()->call_count()); 127 EXPECT_EQ(1, fake_extractor()->call_count());
127 EXPECT_EQ(nullptr, fake_extractor()->last_service()); 128 EXPECT_EQ(nullptr, fake_extractor()->last_service());
128 EXPECT_EQ(nullptr, fake_extractor()->last_signin()); 129 EXPECT_EQ(nullptr, fake_extractor()->last_signin());
129 ValidateAboutInfoCall(); 130 ValidateAboutInfoCall();
130 } 131 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_message_handler.cc ('k') | chrome/browser/ui/webui/sync_internals_ui_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698