| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/chromeos/status/data_promo_notification.h" | 5 #include "chrome/browser/chromeos/status/data_promo_notification.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "chrome/test/base/testing_profile_manager.h" | 13 #include "chrome/test/base/testing_profile_manager.h" |
| 14 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 #include "chromeos/dbus/shill_device_client.h" | 16 #include "chromeos/dbus/shill_device_client.h" |
| 17 #include "chromeos/dbus/shill_service_client.h" | 17 #include "chromeos/dbus/shill_service_client.h" |
| 18 #include "chromeos/login/login_state.h" | 18 #include "chromeos/login/login_state.h" |
| 19 #include "chromeos/network/network_connect.h" |
| 19 #include "chromeos/network/network_state_handler.h" | 20 #include "chromeos/network/network_state_handler.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 #include "ui/chromeos/network/network_connect.h" | |
| 24 #include "ui/message_center/message_center.h" | 24 #include "ui/message_center/message_center.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kCellularDevicePath[] = "/device/stub_cellular_device1"; | 28 const char kCellularDevicePath[] = "/device/stub_cellular_device1"; |
| 29 const char kCellularServicePath[] = "/service/cellular1"; | 29 const char kCellularServicePath[] = "/service/cellular1"; |
| 30 const char kNotificationId[] = "chrome://settings/internet/data_saver"; | 30 const char kNotificationId[] = "chrome://settings/internet/data_saver"; |
| 31 const char kTestUserName[] = "test-user@example.com"; | 31 const char kTestUserName[] = "test-user@example.com"; |
| 32 | 32 |
| 33 class NetworkConnectTestDelegate : public ui::NetworkConnect::Delegate { | 33 class NetworkConnectTestDelegate : public chromeos::NetworkConnect::Delegate { |
| 34 public: | 34 public: |
| 35 NetworkConnectTestDelegate() {} | 35 NetworkConnectTestDelegate() {} |
| 36 ~NetworkConnectTestDelegate() override {} | 36 ~NetworkConnectTestDelegate() override {} |
| 37 | 37 |
| 38 void ShowNetworkConfigure(const std::string& network_id) override {} | 38 void ShowNetworkConfigure(const std::string& network_id) override {} |
| 39 void ShowNetworkSettings(const std::string& network_id) override {} | 39 void ShowNetworkSettings(const std::string& network_id) override {} |
| 40 bool ShowEnrollNetwork(const std::string& network_id) override { | 40 bool ShowEnrollNetwork(const std::string& network_id) override { |
| 41 return false; | 41 return false; |
| 42 } | 42 } |
| 43 void ShowMobileSimDialog() override {} | 43 void ShowMobileSimDialog() override {} |
| 44 void ShowMobileSetupDialog(const std::string& network_id) override {} | 44 void ShowMobileSetupDialog(const std::string& network_id) override {} |
| 45 void ShowNetworkConnectError(const std::string& error_name, |
| 46 const std::string& network_id) override {} |
| 47 void ShowMobileActivationError(const std::string& network_id) override {} |
| 45 | 48 |
| 46 private: | 49 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); | 50 DISALLOW_COPY_AND_ASSIGN(NetworkConnectTestDelegate); |
| 48 }; | 51 }; |
| 49 | 52 |
| 50 } // namespace | 53 } // namespace |
| 51 | 54 |
| 52 namespace chromeos { | 55 namespace chromeos { |
| 53 namespace test { | 56 namespace test { |
| 54 | 57 |
| 55 class DataPromoNotificationTest : public testing::Test { | 58 class DataPromoNotificationTest : public testing::Test { |
| 56 public: | 59 public: |
| 57 DataPromoNotificationTest() {} | 60 DataPromoNotificationTest() {} |
| 58 ~DataPromoNotificationTest() override {} | 61 ~DataPromoNotificationTest() override {} |
| 59 | 62 |
| 60 void SetUp() override { | 63 void SetUp() override { |
| 61 testing::Test::SetUp(); | 64 testing::Test::SetUp(); |
| 62 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 65 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 63 switches::kEnableDataSaverPrompt); | 66 switches::kEnableDataSaverPrompt); |
| 64 DBusThreadManager::Initialize(); | 67 DBusThreadManager::Initialize(); |
| 65 NetworkHandler::Initialize(); | 68 NetworkHandler::Initialize(); |
| 66 data_promo_notification_.reset(new DataPromoNotification); | 69 data_promo_notification_.reset(new DataPromoNotification); |
| 67 SetupUser(); | 70 SetupUser(); |
| 68 SetupNetworkShillState(); | 71 SetupNetworkShillState(); |
| 69 message_center::MessageCenter::Initialize(); | 72 message_center::MessageCenter::Initialize(); |
| 70 base::RunLoop().RunUntilIdle(); | 73 base::RunLoop().RunUntilIdle(); |
| 71 network_connect_delegate_.reset(new NetworkConnectTestDelegate); | 74 network_connect_delegate_.reset(new NetworkConnectTestDelegate); |
| 72 ui::NetworkConnect::Initialize(network_connect_delegate_.get()); | 75 chromeos::NetworkConnect::Initialize(network_connect_delegate_.get()); |
| 73 } | 76 } |
| 74 | 77 |
| 75 void TearDown() override { | 78 void TearDown() override { |
| 76 ui::NetworkConnect::Shutdown(); | 79 chromeos::NetworkConnect::Shutdown(); |
| 77 network_connect_delegate_.reset(); | 80 network_connect_delegate_.reset(); |
| 78 message_center::MessageCenter::Shutdown(); | 81 message_center::MessageCenter::Shutdown(); |
| 79 LoginState::Shutdown(); | 82 LoginState::Shutdown(); |
| 80 profile_manager_.reset(); | 83 profile_manager_.reset(); |
| 81 user_manager_enabler_.reset(); | 84 user_manager_enabler_.reset(); |
| 82 data_promo_notification_.reset(); | 85 data_promo_notification_.reset(); |
| 83 NetworkHandler::Shutdown(); | 86 NetworkHandler::Shutdown(); |
| 84 DBusThreadManager::Shutdown(); | 87 DBusThreadManager::Shutdown(); |
| 85 testing::Test::TearDown(); | 88 testing::Test::TearDown(); |
| 86 } | 89 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 DISALLOW_COPY_AND_ASSIGN(DataPromoNotificationTest); | 149 DISALLOW_COPY_AND_ASSIGN(DataPromoNotificationTest); |
| 147 }; | 150 }; |
| 148 | 151 |
| 149 TEST_F(DataPromoNotificationTest, DataSaverNotification) { | 152 TEST_F(DataPromoNotificationTest, DataSaverNotification) { |
| 150 message_center::MessageCenter* message_center = | 153 message_center::MessageCenter* message_center = |
| 151 message_center::MessageCenter::Get(); | 154 message_center::MessageCenter::Get(); |
| 152 | 155 |
| 153 // Network setup shouldn't be enough to activate notification. | 156 // Network setup shouldn't be enough to activate notification. |
| 154 EXPECT_FALSE(message_center->FindVisibleNotificationById(kNotificationId)); | 157 EXPECT_FALSE(message_center->FindVisibleNotificationById(kNotificationId)); |
| 155 | 158 |
| 156 ui::NetworkConnect::Get()->ConnectToNetwork(kCellularServicePath); | 159 chromeos::NetworkConnect::Get()->ConnectToNetwork(kCellularServicePath); |
| 157 base::RunLoop().RunUntilIdle(); | 160 base::RunLoop().RunUntilIdle(); |
| 158 // Connecting to cellular network (which here makes it the default network) | 161 // Connecting to cellular network (which here makes it the default network) |
| 159 // should trigger the Data Saver notification. | 162 // should trigger the Data Saver notification. |
| 160 EXPECT_TRUE(message_center->FindVisibleNotificationById(kNotificationId)); | 163 EXPECT_TRUE(message_center->FindVisibleNotificationById(kNotificationId)); |
| 161 } | 164 } |
| 162 | 165 |
| 163 } // namespace test | 166 } // namespace test |
| 164 } // namespace chromeos | 167 } // namespace chromeos |
| OLD | NEW |