| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/scoped_mock_time_message_loop_task_runner.h" | 8 #include "base/test/scoped_mock_time_message_loop_task_runner.h" |
| 9 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 9 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 10 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" | 10 #include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 using testing::_; | 25 using testing::_; |
| 26 using testing::AnyNumber; | 26 using testing::AnyNumber; |
| 27 using testing::Return; | 27 using testing::Return; |
| 28 | 28 |
| 29 namespace chromeos { | 29 namespace chromeos { |
| 30 | 30 |
| 31 class NetworkScreenUnitTest : public testing::Test { | 31 class NetworkScreenUnitTest : public testing::Test { |
| 32 public: | 32 public: |
| 33 NetworkScreenUnitTest() {} | 33 NetworkScreenUnitTest() {} |
| 34 | 34 |
| 35 base::ScopedMockTimeMessageLoopTaskRunner* GetTestMessageLoopTaskRunner() { | |
| 36 return &runner_; | |
| 37 } | |
| 38 | |
| 39 void FastForwardTime(base::TimeDelta time) { | |
| 40 runner_.task_runner()->FastForwardBy(time); | |
| 41 } | |
| 42 | |
| 43 // testing::Test: | 35 // testing::Test: |
| 44 void SetUp() override { | 36 void SetUp() override { |
| 45 // Initialize the thread manager. | 37 // Initialize the thread manager. |
| 46 DBusThreadManager::Initialize(); | 38 DBusThreadManager::Initialize(); |
| 47 | 39 |
| 48 // Configure the browser to use Hands-Off Enrollment. | 40 // Configure the browser to use Hands-Off Enrollment. |
| 49 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 41 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 50 switches::kEnterpriseEnableZeroTouchEnrollment, "hands-off"); | 42 switches::kEnterpriseEnableZeroTouchEnrollment, "hands-off"); |
| 51 | 43 |
| 52 // Replace the regular InputMethodManager with a mock. | 44 // Replace the regular InputMethodManager with a mock. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 76 // A pointer to the NetworkScreen. | 68 // A pointer to the NetworkScreen. |
| 77 std::unique_ptr<NetworkScreen> network_screen_; | 69 std::unique_ptr<NetworkScreen> network_screen_; |
| 78 | 70 |
| 79 // Accessory objects needed by NetworkScreen. | 71 // Accessory objects needed by NetworkScreen. |
| 80 MockBaseScreenDelegate mock_base_screen_delegate_; | 72 MockBaseScreenDelegate mock_base_screen_delegate_; |
| 81 login::MockNetworkStateHelper* mock_network_state_helper_ = nullptr; | 73 login::MockNetworkStateHelper* mock_network_state_helper_ = nullptr; |
| 82 | 74 |
| 83 private: | 75 private: |
| 84 // Test versions of core browser infrastructure. | 76 // Test versions of core browser infrastructure. |
| 85 content::TestBrowserThreadBundle threads_; | 77 content::TestBrowserThreadBundle threads_; |
| 86 base::ScopedMockTimeMessageLoopTaskRunner runner_; | |
| 87 | 78 |
| 88 // More accessory objects needed by NetworkScreen. | 79 // More accessory objects needed by NetworkScreen. |
| 89 MockNetworkView mock_view_; | 80 MockNetworkView mock_view_; |
| 90 MockModelViewChannel mock_channel_; | 81 MockModelViewChannel mock_channel_; |
| 91 | 82 |
| 92 // Scoped test versions of required global objects. | 83 // Scoped test versions of required global objects. |
| 93 ScopedTestDeviceSettingsService device_settings_; | 84 ScopedTestDeviceSettingsService device_settings_; |
| 94 ScopedTestCrosSettings cros_settings_; | 85 ScopedTestCrosSettings cros_settings_; |
| 95 system::ScopedFakeStatisticsProvider provider_; | 86 system::ScopedFakeStatisticsProvider provider_; |
| 96 | 87 |
| 97 DISALLOW_COPY_AND_ASSIGN(NetworkScreenUnitTest); | 88 DISALLOW_COPY_AND_ASSIGN(NetworkScreenUnitTest); |
| 98 }; | 89 }; |
| 99 | 90 |
| 100 TEST_F(NetworkScreenUnitTest, ContinuesAutomatically) { | 91 TEST_F(NetworkScreenUnitTest, ContinuesAutomatically) { |
| 101 // Verify that we are using the right TaskRunner. | |
| 102 EXPECT_EQ(GetTestMessageLoopTaskRunner()->task_runner(), | |
| 103 base::MessageLoop::current()->task_runner().get()); | |
| 104 | |
| 105 // Set expectation that NetworkScreen will finish. | 92 // Set expectation that NetworkScreen will finish. |
| 106 EXPECT_CALL(mock_base_screen_delegate_, | 93 EXPECT_CALL(mock_base_screen_delegate_, |
| 107 OnExit(_, ScreenExitCode::NETWORK_CONNECTED, _)) | 94 OnExit(_, ScreenExitCode::NETWORK_CONNECTED, _)) |
| 108 .Times(1); | 95 .Times(1); |
| 109 | 96 |
| 110 // Simulate a network connection. | 97 // Simulate a network connection. |
| 111 EXPECT_CALL(*mock_network_state_helper_, IsConnected()) | 98 EXPECT_CALL(*mock_network_state_helper_, IsConnected()) |
| 112 .Times(AnyNumber()) | 99 .Times(AnyNumber()) |
| 113 .WillRepeatedly((Return(true))); | 100 .WillRepeatedly((Return(true))); |
| 114 network_screen_->UpdateStatus(); | 101 network_screen_->UpdateStatus(); |
| 115 | 102 |
| 116 // Fast forward time by 3 minutes. | |
| 117 FastForwardTime(base::TimeDelta::FromMinutes(3)); | |
| 118 | |
| 119 // Check that we continued once | 103 // Check that we continued once |
| 120 EXPECT_EQ(1, network_screen_->continue_attempts_); | 104 EXPECT_EQ(1, network_screen_->continue_attempts_); |
| 121 } | 105 } |
| 122 | 106 |
| 123 TEST_F(NetworkScreenUnitTest, ContinuesOnlyOnce) { | 107 TEST_F(NetworkScreenUnitTest, ContinuesOnlyOnce) { |
| 124 // Verify that we are using the right TaskRunner. | |
| 125 EXPECT_EQ(GetTestMessageLoopTaskRunner()->task_runner(), | |
| 126 base::MessageLoop::current()->task_runner().get()); | |
| 127 | |
| 128 // Set expectation that NetworkScreen will finish. | 108 // Set expectation that NetworkScreen will finish. |
| 129 EXPECT_CALL(mock_base_screen_delegate_, | 109 EXPECT_CALL(mock_base_screen_delegate_, |
| 130 OnExit(_, ScreenExitCode::NETWORK_CONNECTED, _)) | 110 OnExit(_, ScreenExitCode::NETWORK_CONNECTED, _)) |
| 131 .Times(1); | 111 .Times(1); |
| 132 | 112 |
| 133 // Connect to network "net0". | 113 // Connect to network "net0". |
| 134 EXPECT_CALL(*mock_network_state_helper_, GetCurrentNetworkName()) | 114 EXPECT_CALL(*mock_network_state_helper_, GetCurrentNetworkName()) |
| 135 .Times(AnyNumber()) | 115 .Times(AnyNumber()) |
| 136 .WillRepeatedly(Return(base::ASCIIToUTF16("net0"))); | 116 .WillRepeatedly(Return(base::ASCIIToUTF16("net0"))); |
| 137 EXPECT_CALL(*mock_network_state_helper_, IsConnected()) | 117 EXPECT_CALL(*mock_network_state_helper_, IsConnected()) |
| 138 .Times(AnyNumber()) | 118 .Times(AnyNumber()) |
| 139 .WillRepeatedly(Return(true)); | 119 .WillRepeatedly(Return(true)); |
| 140 | 120 |
| 141 // Stop waiting for net0. | 121 // Stop waiting for net0. |
| 142 network_screen_->StopWaitingForConnection(base::ASCIIToUTF16("net0")); | 122 network_screen_->StopWaitingForConnection(base::ASCIIToUTF16("net0")); |
| 143 | 123 |
| 144 // Fast forward time by 3 minutes. | |
| 145 FastForwardTime(base::TimeDelta::FromMinutes(3)); | |
| 146 | |
| 147 // Check that we have continued exactly once. | 124 // Check that we have continued exactly once. |
| 148 ASSERT_EQ(1, network_screen_->continue_attempts_); | 125 ASSERT_EQ(1, network_screen_->continue_attempts_); |
| 149 | 126 |
| 150 // Stop waiting for another network, net1. | 127 // Stop waiting for another network, net1. |
| 151 network_screen_->StopWaitingForConnection(base::ASCIIToUTF16("net1")); | 128 network_screen_->StopWaitingForConnection(base::ASCIIToUTF16("net1")); |
| 152 | 129 |
| 153 // Fast forward time by 3 minutes. | |
| 154 FastForwardTime(base::TimeDelta::FromMinutes(3)); | |
| 155 | |
| 156 // Check that we have still continued only once. | 130 // Check that we have still continued only once. |
| 157 EXPECT_EQ(1, network_screen_->continue_attempts_); | 131 EXPECT_EQ(1, network_screen_->continue_attempts_); |
| 158 } | 132 } |
| 159 | 133 |
| 160 } // namespace chromeos | 134 } // namespace chromeos |
| OLD | NEW |