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

Unified Diff: chrome/browser/chromeos/status/data_promo_notification_unittest.cc

Issue 1108123003: Unit test for Data Saver prompt notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address reviewer comments Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/status/data_promo_notification_unittest.cc
diff --git a/chrome/browser/chromeos/status/data_promo_notification_unittest.cc b/chrome/browser/chromeos/status/data_promo_notification_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0b7955586425c432117ba4bddbc3d49384495a5e
--- /dev/null
+++ b/chrome/browser/chromeos/status/data_promo_notification_unittest.cc
@@ -0,0 +1,160 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/status/data_promo_notification.h"
+
+#include "base/command_line.h"
+#include "base/run_loop.h"
+#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
+#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_profile_manager.h"
+#include "chromeos/chromeos_switches.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/shill_device_client.h"
+#include "chromeos/dbus/shill_service_client.h"
+#include "chromeos/login/login_state.h"
+#include "chromeos/network/network_state_handler.h"
+#include "testing/platform_test.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
+#include "ui/chromeos/network/network_connect.h"
+#include "ui/message_center/message_center.h"
+
+namespace {
+
+const char kCellularDevicePath[] = "/device/stub_cellular_device1";
+const char kCellularServicePath[] = "/service/cellular1";
+const char kNotificationId[] = "chrome://settings/internet/data_saver";
+const char kTestUserName[] = "test-user@example.com";
+
+class NetworkConnectTestDelegate : public ui::NetworkConnect::Delegate {
+ public:
+ NetworkConnectTestDelegate() {}
+ ~NetworkConnectTestDelegate() override {}
+
+ void ShowNetworkConfigure(const std::string& network_id) override {}
+ void ShowNetworkSettingsForGuid(const std::string& network_id) override {}
+ bool ShowEnrollNetwork(const std::string& network_id) override {
+ return false;
+ }
+ void ShowMobileSimDialog() override {}
+ void ShowMobileSetupDialog(const std::string& service_path) override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate);
+};
+
+} // namespace
+
+namespace chromeos {
+namespace test {
+
+class DataPromoNotificationTest : public testing::Test {
+ public:
+ DataPromoNotificationTest() {}
+ ~DataPromoNotificationTest() override {}
+
+ void SetUp() override {
+ testing::Test::SetUp();
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableDataSaverPrompt);
+ DBusThreadManager::Initialize();
+ NetworkHandler::Initialize();
+ data_promo_notification_.reset(new DataPromoNotification);
+ SetupUser();
+ SetupNetworkShillState();
+ message_center::MessageCenter::Initialize();
+ base::RunLoop().RunUntilIdle();
+ network_connect_delegate_.reset(new NetworkConnectTestDelegate);
+ ui::NetworkConnect::Initialize(network_connect_delegate_.get());
+ }
+
+ void TearDown() override {
+ ui::NetworkConnect::Shutdown();
+ network_connect_delegate_.reset();
+ message_center::MessageCenter::Shutdown();
+ LoginState::Shutdown();
+ profile_manager_.reset();
+ user_manager_enabler_.reset();
+ data_promo_notification_.reset();
+ NetworkHandler::Shutdown();
+ DBusThreadManager::Shutdown();
+ testing::Test::TearDown();
+ }
+
+ protected:
+ void SetupUser() {
+ scoped_ptr<FakeChromeUserManager> user_manager(new FakeChromeUserManager());
+ user_manager->AddUser(kTestUserName);
+ user_manager->LoginUser(kTestUserName);
+ user_manager_enabler_.reset(
+ new ScopedUserManagerEnabler(user_manager.release()));
+
+ profile_manager_.reset(
+ new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
+ ASSERT_TRUE(profile_manager_->SetUp());
+ profile_manager_->SetLoggedIn(true);
+ ASSERT_TRUE(user_manager::UserManager::Get()->GetPrimaryUser());
+
+ LoginState::Initialize();
+ LoginState::Get()->SetLoggedInState(LoginState::LOGGED_IN_ACTIVE,
+ LoginState::LOGGED_IN_USER_REGULAR);
+ }
+
+ void SetupNetworkShillState() {
+ base::RunLoop().RunUntilIdle();
+
+ // Create a cellular device with provider.
+ ShillDeviceClient::TestInterface* device_test =
+ DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
+ device_test->ClearDevices();
+ device_test->AddDevice(kCellularDevicePath, shill::kTypeCellular,
+ "stub_cellular_device1");
+ base::DictionaryValue home_provider;
+ home_provider.SetString("name", "Cellular1_Provider");
+ home_provider.SetString("country", "us");
+ device_test->SetDeviceProperty(kCellularDevicePath,
+ shill::kHomeProviderProperty, home_provider);
+
+ // Create a cellular network and activate it.
+ ShillServiceClient::TestInterface* service_test =
+ DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
+ service_test->ClearServices();
+ service_test->AddService(kCellularServicePath, "cellular1_guid",
+ "cellular1" /* name */, shill::kTypeCellular,
+ "activated", true /* visible */);
+ service_test->SetServiceProperty(
+ kCellularServicePath, shill::kActivationStateProperty,
+ base::StringValue(shill::kActivationStateActivated));
+ service_test->SetServiceProperty(kCellularServicePath,
+ shill::kConnectableProperty,
+ base::FundamentalValue(true));
+ }
+
+ scoped_ptr<DataPromoNotification> data_promo_notification_;
+ scoped_ptr<NetworkConnectTestDelegate> network_connect_delegate_;
+ scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
+ scoped_ptr<TestingProfileManager> profile_manager_;
+ base::MessageLoop message_loop_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DataPromoNotificationTest);
+};
+
+TEST_F(DataPromoNotificationTest, DataSaverNotification) {
+ message_center::MessageCenter* message_center =
+ message_center::MessageCenter::Get();
+
+ // Network setup shouldn't be enough to activate notification.
+ EXPECT_FALSE(message_center->FindVisibleNotificationById(kNotificationId));
+
+ ui::NetworkConnect::Get()->ConnectToNetwork(kCellularServicePath);
+ base::RunLoop().RunUntilIdle();
+ // Connecting to cellular network (which here makes it the default network)
+ // should trigger the Data Saver notification.
+ EXPECT_TRUE(message_center->FindVisibleNotificationById(kNotificationId));
+}
+
+} // namespace test
+} // namespace chromeos
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698