diff options
author | nkostylev@google.com <nkostylev@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 14:39:04 +0000 |
---|---|---|
committer | nkostylev@google.com <nkostylev@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 14:39:04 +0000 |
commit | 5760db1c137ab907e01b307a9440fa3b114fa892 (patch) | |
tree | cee534a03d348b3c80a163d9d6f4ca9ae07ee675 /chrome/browser | |
parent | 442446065dbbd6f67ec95ace7e5e22b66dfbd6d8 (diff) | |
download | chromium_src-5760db1c137ab907e01b307a9440fa3b114fa892.zip chromium_src-5760db1c137ab907e01b307a9440fa3b114fa892.tar.gz chromium_src-5760db1c137ab907e01b307a9440fa3b114fa892.tar.bz2 |
Add "Enable WiFi" item on welcome screen.
BUG= http://crosbug.com/4033
TEST=When WiFi was disabled through network status area button it's possible to enable it back.
Review URL: http://codereview.chromium.org/2850012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50104 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/chromeos/login/network_screen.cc | 37 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_screen.h | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_screen_browsertest.cc | 59 |
3 files changed, 99 insertions, 3 deletions
diff --git a/chrome/browser/chromeos/login/network_screen.cc b/chrome/browser/chromeos/login/network_screen.cc index a28a136..718ed20 100644 --- a/chrome/browser/chromeos/login/network_screen.cc +++ b/chrome/browser/chromeos/login/network_screen.cc @@ -30,6 +30,7 @@ namespace chromeos { NetworkScreen::NetworkScreen(WizardScreenDelegate* delegate, bool is_out_of_box) : ViewScreen<NetworkSelectionView>(delegate), is_network_subscribed_(false), + wifi_disabled_(false), is_out_of_box_(is_out_of_box), is_waiting_for_connect_(false), ethernet_preselected_(false), @@ -47,7 +48,9 @@ NetworkScreen::~NetworkScreen() { int NetworkScreen::GetItemCount() { // Item with index = 0 is either "no networks are available" or // "no selection". - return static_cast<int>(networks_.GetNetworkCount()) + 1; + // If WiFi is disabled adding extra item to enable it. + return static_cast<int>(networks_.GetNetworkCount()) + 1 + + (wifi_disabled_ ? 1 : 0); } std::wstring NetworkScreen::GetItemAt(int index) { @@ -56,6 +59,12 @@ std::wstring NetworkScreen::GetItemAt(int index) { l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE) : l10n_util::GetString(IDS_NETWORK_SELECTION_NONE); } + if (wifi_disabled_ && + index == static_cast<int>(networks_.GetNetworkCount()) + 1) { + return l10n_util::GetStringF( + IDS_STATUSBAR_NETWORK_DEVICE_ENABLE, + l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_WIFI)); + } NetworkList::NetworkItem* network = networks_.GetNetworkAt(index - 1); return network ? UTF16ToWide(network->label) : std::wstring(); @@ -72,6 +81,14 @@ void NetworkScreen::ItemChanged(views::Combobox* sender, if (new_index == prev_index || new_index <= 0 || prev_index < 0) return; + if (wifi_disabled_ && + new_index == static_cast<int>(networks_.GetNetworkCount()) + 1) { + view()->EnableContinue(false); + MessageLoop::current()->PostTask(FROM_HERE, + task_factory_.NewRunnableMethod(&NetworkScreen::EnableWiFi)); + return; + } + if (networks_.IsEmpty()) return; @@ -113,6 +130,10 @@ void NetworkScreen::NetworkChanged(NetworkLibrary* network_lib) { if (!view()) return; + // TODO(nkostylev): Reuse network menu button - http://crosbug.com/4133 + wifi_disabled_ = !chromeos::CrosLibrary::Get()-> + GetNetworkLibrary()->wifi_enabled(); + // Save network selection in case it would be available after refresh. NetworkList::NetworkType network_type = NetworkList::NETWORK_EMPTY; string16 network_id; @@ -146,6 +167,7 @@ void NetworkScreen::NetworkChanged(NetworkLibrary* network_lib) { // NetworkLibrary::Observer implementation: void NetworkScreen::OnDialogCancelled() { + view()->EnableContinue(false); view()->SetSelectedNetworkItem(0); } @@ -165,8 +187,10 @@ NetworkSelectionView* NetworkScreen::AllocateView() { // NetworkScreen, public: void NetworkScreen::Refresh() { - SubscribeNetworkNotification(); - NetworkChanged(chromeos::CrosLibrary::Get()->GetNetworkLibrary()); + if (CrosLibrary::Get()->EnsureLoaded()) { + SubscribeNetworkNotification(); + NetworkChanged(chromeos::CrosLibrary::Get()->GetNetworkLibrary()); + } } //////////////////////////////////////////////////////////////////////////////// @@ -194,6 +218,13 @@ void NetworkScreen::ConnectToNetwork(NetworkList::NetworkType type, } } +void NetworkScreen::EnableWiFi() { + if (CrosLibrary::Get()->EnsureLoaded()) { + chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> + EnableWifiNetworkDevice(true); + } +} + void NetworkScreen::SubscribeNetworkNotification() { if (!is_network_subscribed_) { is_network_subscribed_ = true; diff --git a/chrome/browser/chromeos/login/network_screen.h b/chrome/browser/chromeos/login/network_screen.h index 973fbc4..7c1e298 100644 --- a/chrome/browser/chromeos/login/network_screen.h +++ b/chrome/browser/chromeos/login/network_screen.h @@ -66,6 +66,9 @@ class NetworkScreen : public ViewScreen<NetworkSelectionView>, // Connects to network if needed and updates screen state. void ConnectToNetwork(NetworkList::NetworkType type, const string16& id); + // Enables WiFi device. + void EnableWiFi(); + // Subscribes to network change notifications. void SubscribeNetworkNotification(); @@ -101,6 +104,9 @@ class NetworkScreen : public ViewScreen<NetworkSelectionView>, // Networks model, contains current state of available networks. NetworkList networks_; + // True if WiFi is currently disabled. + bool wifi_disabled_; + // True if full OOBE flow should be shown. bool is_out_of_box_; diff --git a/chrome/browser/chromeos/login/network_screen_browsertest.cc b/chrome/browser/chromeos/login/network_screen_browsertest.cc index b7ba053..7a7694b 100644 --- a/chrome/browser/chromeos/login/network_screen_browsertest.cc +++ b/chrome/browser/chromeos/login/network_screen_browsertest.cc @@ -76,6 +76,9 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { EXPECT_CALL(*mock_network_library_, ethernet_connecting()) .Times(1) .WillOnce((Return(false))); + EXPECT_CALL(*mock_network_library_, wifi_enabled()) + .Times(1) + .WillOnce((Return(true))); EXPECT_CALL(*mock_network_library_, wifi_networks()) .Times(1) .WillOnce((ReturnRef(wifi_networks_))); @@ -95,6 +98,12 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { test_api()->SetLoginLibrary(NULL, false); } + void NetworkChangedExpectations(bool wifi_enabled) { + EXPECT_CALL(*mock_network_library_, wifi_enabled()) + .Times(1) + .WillOnce((Return(wifi_enabled))); + } + void EthernetExpectations(bool connected, bool connecting) { EXPECT_CALL(*mock_network_library_, ethernet_connected()) .Times(1) @@ -199,6 +208,39 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, Basic) { network_screen->GetItemAt(0)); } +IN_PROC_BROWSER_TEST_F(NetworkScreenTest, EnableWifi) { + ASSERT_TRUE(controller()); + NetworkScreen* network_screen = controller()->GetNetworkScreen(); + ASSERT_TRUE(network_screen != NULL); + ASSERT_EQ(network_screen, controller()->current_screen()); + NetworkSelectionView* network_view = network_screen->view(); + ASSERT_TRUE(network_view != NULL); + NetworkLibrary* network_library = + chromeos::CrosLibrary::Get()->GetNetworkLibrary(); + + // WiFi is disabled. + NetworkChangedExpectations(false); + EthernetExpectations(false, false); + WifiCellularNetworksExpectations(); + network_screen->NetworkChanged(network_library); + ASSERT_EQ(2, network_screen->GetItemCount()); + EXPECT_EQ(l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE), + network_screen->GetItemAt(0)); + EXPECT_EQ(l10n_util::GetStringF(IDS_STATUSBAR_NETWORK_DEVICE_ENABLE, + l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_WIFI)), + network_screen->GetItemAt(1)); + + // Emulate "Enable Wifi" item press. + EXPECT_CALL(*mock_network_library_, EnableWifiNetworkDevice(true)) + .Times(1); + DummyComboboxModel combobox_model; + views::Combobox combobox(&combobox_model); + network_screen->ItemChanged(&combobox, 0, 1); + network_view->SetSelectedNetworkItem(1); + ui_test_utils::RunAllPendingInMessageLoop(); + ASSERT_EQ(network_screen, controller()->current_screen()); +} + IN_PROC_BROWSER_TEST_F(NetworkScreenTest, NetworksConnectedNotSelected) { ASSERT_TRUE(controller()); NetworkLibrary* network_library = @@ -210,6 +252,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, NetworksConnectedNotSelected) { EthernetExpectations(true, false); WifiCellularNetworksExpectations(); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); // Ethernet is preselected once. EXPECT_EQ(1, network_view->GetSelectedNetworkItem()); @@ -227,6 +270,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, NetworksConnectedNotSelected) { WifiCellularNetworksExpectations(); WifiSsidExpectation(wifi_.name()); CellularNameExpectation(cellular_.name()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(network_screen, controller()->current_screen()); ASSERT_EQ(3, network_screen->GetItemCount()); @@ -240,6 +284,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, NetworksConnectedNotSelected) { WifiCellularNetworksExpectations(); WifiSsidExpectation(wifi_.name()); CellularNameExpectation(cellular_.name()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(network_screen, controller()->current_screen()); ASSERT_EQ(4, network_screen->GetItemCount()); @@ -263,6 +308,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, EthernetSelected) { // Emulate connecting to Ethernet. EthernetExpectations(false, true); WifiCellularNetworksExpectations(); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); EXPECT_EQ(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET), @@ -280,6 +326,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, EthernetSelected) { // Emulate connected Ethernet - it should be preselected. EthernetExpectations(true, false); WifiCellularNetworksExpectations(); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); EXPECT_EQ(1, network_view->GetSelectedNetworkItem()); @@ -302,6 +349,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiSelected) { SetupWifiNetwork(false, false); WifiCellularNetworksExpectations(); WifiSsidExpectation(std::string()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); EXPECT_EQ(ASCIIToWide(wifi_.name()), network_screen->GetItemAt(1)); @@ -320,6 +368,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiSelected) { string16())) .Times(1); ui_test_utils::RunAllPendingInMessageLoop(); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); @@ -329,6 +378,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiSelected) { WifiExpectations(false, true); WifiCellularNetworksExpectations(); WifiSsidExpectation(wifi_.name()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(network_screen, controller()->current_screen()); @@ -338,6 +388,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiSelected) { WifiExpectations(true, false); WifiCellularNetworksExpectations(); WifiSsidExpectation(wifi_.name()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ui_test_utils::RunAllPendingInMessageLoop(); ASSERT_EQ(network_screen, controller()->current_screen()); @@ -359,6 +410,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, CellularSelected) { SetupCellularNetwork(false, false); WifiCellularNetworksExpectations(); CellularNameExpectation(std::string()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); EXPECT_EQ(ASCIIToWide(cellular_.name()), network_screen->GetItemAt(1)); @@ -375,6 +427,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, CellularSelected) { EXPECT_CALL(*mock_network_library_, ConnectToCellularNetwork(_)) .Times(1); ui_test_utils::RunAllPendingInMessageLoop(); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); @@ -384,6 +437,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, CellularSelected) { CellularExpectations(false, true); WifiCellularNetworksExpectations(); CellularNameExpectation(cellular_.name()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(network_screen, controller()->current_screen()); @@ -393,6 +447,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, CellularSelected) { CellularExpectations(true, false); WifiCellularNetworksExpectations(); CellularNameExpectation(cellular_.name()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ui_test_utils::RunAllPendingInMessageLoop(); ASSERT_EQ(network_screen, controller()->current_screen()); @@ -414,6 +469,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiWaiting) { SetupWifiNetwork(false, false); WifiCellularNetworksExpectations(); WifiSsidExpectation(std::string()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); DummyComboboxModel combobox_model; @@ -430,6 +486,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiWaiting) { string16())) .Times(1); ui_test_utils::RunAllPendingInMessageLoop(); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); @@ -439,6 +496,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiWaiting) { WifiExpectations(false, true); WifiCellularNetworksExpectations(); WifiSsidExpectation(wifi_.name()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); // Continue but wait for connection. @@ -463,6 +521,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiWaiting) { WifiExpectations(true, false); WifiCellularNetworksExpectations(); WifiSsidExpectation(wifi_.name()); + NetworkChangedExpectations(true); network_screen->NetworkChanged(network_library); ui_test_utils::RunAllPendingInMessageLoop(); controller()->set_observer(NULL); |