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

Side by Side Diff: chrome/browser/ui/webui/settings/settings_manage_profile_handler_unittest.cc

Issue 1988463002: MD Settings: Convert C++ handlers to be JavaScript-lifecycle aware. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/settings/settings_manage_profile_handler.h" 5 #include "chrome/browser/ui/webui/settings/settings_manage_profile_handler.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/common/pref_names.h" 8 #include "chrome/common/pref_names.h"
9 #include "chrome/test/base/testing_browser_process.h" 9 #include "chrome/test/base/testing_browser_process.h"
10 #include "chrome/test/base/testing_profile_manager.h" 10 #include "chrome/test/base/testing_profile_manager.h"
11 #include "components/prefs/pref_service.h" 11 #include "components/prefs/pref_service.h"
12 #include "content/public/browser/web_ui_data_source.h" 12 #include "content/public/browser/web_ui_data_source.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "content/public/test/test_web_ui.h" 14 #include "content/public/test/test_web_ui.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace settings { 17 namespace settings {
18 18
19 namespace { 19 namespace {
20 20
21 class TestManageProfileHandler : public ManageProfileHandler { 21 class TestManageProfileHandler : public ManageProfileHandler {
22 public: 22 public:
23 explicit TestManageProfileHandler(Profile* profile) 23 explicit TestManageProfileHandler(Profile* profile)
24 : ManageProfileHandler(profile) {} 24 : ManageProfileHandler(profile) {}
25 25
26 using ManageProfileHandler::set_web_ui; 26 using ManageProfileHandler::set_web_ui;
27 using ManageProfileHandler::AllowJavascript;
27 }; 28 };
28 29
29 } // namespace 30 } // namespace
30 31
31 class ManageProfileHandlerTest : public testing::Test { 32 class ManageProfileHandlerTest : public testing::Test {
32 public: 33 public:
33 ManageProfileHandlerTest() 34 ManageProfileHandlerTest()
34 : profile_manager_(TestingBrowserProcess::GetGlobal()), 35 : profile_manager_(TestingBrowserProcess::GetGlobal()),
35 profile_(nullptr) {} 36 profile_(nullptr) {}
36 37
37 void SetUp() override { 38 void SetUp() override {
38 ASSERT_TRUE(profile_manager_.SetUp()); 39 ASSERT_TRUE(profile_manager_.SetUp());
39 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); 40 profile_ = profile_manager_.CreateTestingProfile("Profile 1");
40 41
41 handler_.reset(new TestManageProfileHandler(profile_)); 42 handler_.reset(new TestManageProfileHandler(profile_));
42 handler_->set_web_ui(&web_ui_); 43 handler_->set_web_ui(&web_ui_);
44 handler()->AllowJavascript();
45 web_ui()->ClearTrackedCalls();
43 } 46 }
44 47
45 void VerifyIconList(const base::Value* value) { 48 void VerifyIconList(const base::Value* value) {
46 const base::ListValue* icon_urls = nullptr; 49 const base::ListValue* icon_urls = nullptr;
47 ASSERT_TRUE(value->GetAsList(&icon_urls)); 50 ASSERT_TRUE(value->GetAsList(&icon_urls));
48 51
49 // Expect the list of icon URLs to be a non-empty list of non-empty strings. 52 // Expect the list of icon URLs to be a non-empty list of non-empty strings.
50 EXPECT_FALSE(icon_urls->empty()); 53 EXPECT_FALSE(icon_urls->empty());
51 for (size_t i = 0; i < icon_urls->GetSize(); ++i) { 54 for (size_t i = 0; i < icon_urls->GetSize(); ++i) {
52 std::string icon_url; 55 std::string icon_url;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); 112 EXPECT_EQ("cr.webUIListenerCallback", data.function_name());
110 113
111 std::string event_id; 114 std::string event_id;
112 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); 115 ASSERT_TRUE(data.arg1()->GetAsString(&event_id));
113 EXPECT_EQ("available-icons-changed", event_id); 116 EXPECT_EQ("available-icons-changed", event_id);
114 117
115 VerifyIconList(data.arg2()); 118 VerifyIconList(data.arg2());
116 } 119 }
117 120
118 } // namespace settings 121 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698