| OLD | NEW |
| 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 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | 5 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) |
| 6 | 6 |
| 7 #include "chrome/browser/ui/webui/settings/metrics_reporting_handler.h" | 7 #include "chrome/browser/ui/webui/settings/metrics_reporting_handler.h" |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 EXPECT_CALL(provider_, IsInitializationComplete(testing::_)).WillRepeatedly( | 45 EXPECT_CALL(provider_, IsInitializationComplete(testing::_)).WillRepeatedly( |
| 46 testing::Return(true)); | 46 testing::Return(true)); |
| 47 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 47 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void SetUp() override { | 50 void SetUp() override { |
| 51 ASSERT_EQ(local_state(), g_browser_process->local_state()); | 51 ASSERT_EQ(local_state(), g_browser_process->local_state()); |
| 52 EXPECT_TRUE(test_web_ui()->call_data().empty()); | 52 EXPECT_TRUE(test_web_ui()->call_data().empty()); |
| 53 | 53 |
| 54 base::ListValue args; | 54 base::ListValue args; |
| 55 args.Append(base::WrapUnique(new base::FundamentalValue(1))); | 55 args.Append(base::MakeUnique<base::FundamentalValue>(1)); |
| 56 handler()->HandleGetMetricsReporting(&args); | 56 handler()->HandleGetMetricsReporting(&args); |
| 57 | 57 |
| 58 EXPECT_TRUE(handler()->IsJavascriptAllowed()); | 58 EXPECT_TRUE(handler()->IsJavascriptAllowed()); |
| 59 EXPECT_EQ(1u, test_web_ui()->call_data().size()); | 59 EXPECT_EQ(1u, test_web_ui()->call_data().size()); |
| 60 | 60 |
| 61 test_web_ui()->ClearTrackedCalls(); | 61 test_web_ui()->ClearTrackedCalls(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void TearDown() override { | 64 void TearDown() override { |
| 65 // For crbug.com/637068 which only run on official bots with no try jobs. | 65 // For crbug.com/637068 which only run on official bots with no try jobs. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Toggle the pref again, while JavaScript is disabled. | 99 // Toggle the pref again, while JavaScript is disabled. |
| 100 local_state()->SetBoolean( | 100 local_state()->SetBoolean( |
| 101 metrics::prefs::kMetricsReportingEnabled, | 101 metrics::prefs::kMetricsReportingEnabled, |
| 102 !local_state()->GetBoolean(metrics::prefs::kMetricsReportingEnabled)); | 102 !local_state()->GetBoolean(metrics::prefs::kMetricsReportingEnabled)); |
| 103 EXPECT_TRUE(test_web_ui()->call_data().empty()); | 103 EXPECT_TRUE(test_web_ui()->call_data().empty()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 TEST_F(MetricsReportingHandlerTest, PolicyChangesNotifyPage) { | 106 TEST_F(MetricsReportingHandlerTest, PolicyChangesNotifyPage) { |
| 107 // Change the policy, check that the page was notified. | 107 // Change the policy, check that the page was notified. |
| 108 map()->Set(policy::key::kMetricsReportingEnabled, | 108 map()->Set(policy::key::kMetricsReportingEnabled, |
| 109 policy::POLICY_LEVEL_MANDATORY, | 109 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 110 policy::POLICY_SCOPE_USER, | |
| 111 policy::POLICY_SOURCE_CLOUD, | 110 policy::POLICY_SOURCE_CLOUD, |
| 112 base::WrapUnique(new base::FundamentalValue(true)), | 111 base::MakeUnique<base::FundamentalValue>(true), nullptr); |
| 113 nullptr); | |
| 114 provider()->UpdateChromePolicy(*map()); | 112 provider()->UpdateChromePolicy(*map()); |
| 115 EXPECT_EQ(1u, test_web_ui()->call_data().size()); | 113 EXPECT_EQ(1u, test_web_ui()->call_data().size()); |
| 116 | 114 |
| 117 test_web_ui()->ClearTrackedCalls(); | 115 test_web_ui()->ClearTrackedCalls(); |
| 118 handler()->DisallowJavascript(); | 116 handler()->DisallowJavascript(); |
| 119 | 117 |
| 120 // Policies changing while JavaScript is disabled shouldn't notify the page. | 118 // Policies changing while JavaScript is disabled shouldn't notify the page. |
| 121 map()->Set(policy::key::kMetricsReportingEnabled, | 119 map()->Set(policy::key::kMetricsReportingEnabled, |
| 122 policy::POLICY_LEVEL_MANDATORY, | 120 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 123 policy::POLICY_SCOPE_USER, | |
| 124 policy::POLICY_SOURCE_CLOUD, | 121 policy::POLICY_SOURCE_CLOUD, |
| 125 base::WrapUnique(new base::FundamentalValue(false)), | 122 base::MakeUnique<base::FundamentalValue>(false), nullptr); |
| 126 nullptr); | |
| 127 provider()->UpdateChromePolicy(*map()); | 123 provider()->UpdateChromePolicy(*map()); |
| 128 EXPECT_TRUE(test_web_ui()->call_data().empty()); | 124 EXPECT_TRUE(test_web_ui()->call_data().empty()); |
| 129 } | 125 } |
| 130 | 126 |
| 131 } // namespace settings | 127 } // namespace settings |
| 132 | 128 |
| 133 #endif // defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | 129 #endif // defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) |
| OLD | NEW |