diff options
author | nkostylev@google.com <nkostylev@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-25 13:50:44 +0000 |
---|---|---|
committer | nkostylev@google.com <nkostylev@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-25 13:50:44 +0000 |
commit | a697dcc6b45d4831d3fd53afe8f6463461b3ed0f (patch) | |
tree | 4d996fdc93dd7b791ddfcf72b3ac66f2761bb8d1 /chrome | |
parent | 79ea90be68675c0366173334b269f15f156e2dbf (diff) | |
download | chromium_src-a697dcc6b45d4831d3fd53afe8f6463461b3ed0f.zip chromium_src-a697dcc6b45d4831d3fd53afe8f6463461b3ed0f.tar.gz chromium_src-a697dcc6b45d4831d3fd53afe8f6463461b3ed0f.tar.bz2 |
Update welcome screen based on mocks.
- Wizard is proceed to the next screen once "Continue" button is clicked and selected network is connected.
- Preselect Ethernet if it's connected.
- Clear selection when encrypted network dialog has been cancelled.
- Ask for network selection when connection timed out.
- Support list of connected/connecting networks.
BUG=cros:3279, cros:3306
TEST=Welcome screen & network selection should work.
Review URL: http://codereview.chromium.org/2077019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48146 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/generated_resources.grd | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_screen.cc | 113 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_screen.h | 37 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_screen_browsertest.cc | 164 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_selection_view.cc | 39 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_selection_view.h | 9 | ||||
-rw-r--r-- | chrome/browser/chromeos/network_list.cc | 130 | ||||
-rw-r--r-- | chrome/browser/chromeos/network_list.h | 42 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/network_config_view.cc | 14 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/network_config_view.h | 14 |
10 files changed, 394 insertions, 171 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 1f573a6..98fb000 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -7307,6 +7307,9 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_NETWORK_SELECTION_OFFLINE_BUTTON" desc="Text shown on work offline button"> Work offline </message> + <message name="IDS_NETWORK_SELECTION_CONTINUE_BUTTON" desc="Text shown on continue button"> + Continue >> + </message> <message name="IDS_LOGIN_TITLE"> Sign in with your Google account </message> diff --git a/chrome/browser/chromeos/login/network_screen.cc b/chrome/browser/chromeos/login/network_screen.cc index a17d4d8..6cde949 100644 --- a/chrome/browser/chromeos/login/network_screen.cc +++ b/chrome/browser/chromeos/login/network_screen.cc @@ -10,11 +10,18 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/login/network_selection_view.h" #include "chrome/browser/chromeos/login/screen_observer.h" -#include "chrome/browser/chromeos/options/network_config_view.h" #include "grit/generated_resources.h" #include "views/widget/widget.h" #include "views/window/window.h" + +namespace { + +// Time in seconds for connection timeout. +const int kConnectionTimeoutSec = 10; + +} // namespace + namespace chromeos { /////////////////////////////////////////////////////////////////////////////// @@ -24,6 +31,8 @@ NetworkScreen::NetworkScreen(WizardScreenDelegate* delegate, bool is_out_of_box) : ViewScreen<NetworkSelectionView>(delegate), is_network_subscribed_(false), is_out_of_box_(is_out_of_box), + is_waiting_for_connect_(false), + ethernet_preselected_(false), ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { } @@ -57,6 +66,7 @@ std::wstring NetworkScreen::GetItemAt(int index) { void NetworkScreen::ItemChanged(views::Combobox* sender, int prev_index, int new_index) { + view()->EnableContinue(new_index > 0); // Corner case: item with index 0 is "No selection". Just select it. if (new_index == prev_index || new_index <= 0 || prev_index < 0) return; @@ -64,6 +74,7 @@ void NetworkScreen::ItemChanged(views::Combobox* sender, if (networks_.IsEmpty()) return; + // Connect to network as early as possible. const NetworkList::NetworkItem* network = networks_.GetNetworkAt(new_index - 1); MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod( @@ -75,8 +86,23 @@ void NetworkScreen::ItemChanged(views::Combobox* sender, void NetworkScreen::ButtonPressed(views::Button* sender, const views::Event& event) { - MessageLoop::current()->PostTask(FROM_HERE, - task_factory_.NewRunnableMethod(&NetworkScreen::NotifyOnOffline)); + // Proceed only when selected network is connected. + const NetworkList::NetworkItem* network = GetSelectedNetwork(); + if (!network) + return; + if (networks_.IsNetworkConnected(network->network_type, network->label)) { + MessageLoop::current()->PostTask(FROM_HERE, + task_factory_.NewRunnableMethod(&NetworkScreen::NotifyOnConnection)); + } else { + WaitForConnection(network); + if (!networks_.IsNetworkConnecting(network->network_type, network->label)) { + MessageLoop::current()->PostTask( + FROM_HERE, + task_factory_.NewRunnableMethod(&NetworkScreen::ConnectToNetwork, + network->network_type, + network->label)); + } + } } //////////////////////////////////////////////////////////////////////////////// @@ -92,25 +118,31 @@ void NetworkScreen::NetworkChanged(NetworkLibrary* network_lib) { network_id = selected_network->label; } networks_.NetworkChanged(network_lib); - // TODO(nkostylev): Check for connection error. - // For initial out of box experience make sure that network was selected. - if (networks_.ConnectedNetwork() && - (selected_network || !is_out_of_box_)) { + if (is_waiting_for_connect_ && + networks_.IsNetworkConnected(connecting_network_.network_type, + connecting_network_.label)) { + // Stop waiting & don't update spinner status. + StopWaitingForConnection(false); MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod(&NetworkScreen::NotifyOnConnection)); return; } - const NetworkList::NetworkItem* network = networks_.ConnectingNetwork(); - if (network && - (selected_network || !is_out_of_box_)) { - view()->ShowConnectingStatus(true, network->label); - } view()->NetworkModelChanged(); - SelectNetwork(network_type, network_id); + // Prefer Ethernet when it's connected (only once). + if (!ethernet_preselected_ && + networks_.IsNetworkConnected(NetworkList::NETWORK_ETHERNET, string16())) { + ethernet_preselected_ = true; + SelectNetwork(NetworkList::NETWORK_ETHERNET, string16()); + } else { + SelectNetwork(network_type, network_id); + } } -void NetworkScreen::NetworkTraffic(NetworkLibrary* cros, - int traffic_type) { +//////////////////////////////////////////////////////////////////////////////// +// NetworkLibrary::Observer implementation: + +void NetworkScreen::OnDialogCancelled() { + view()->SetSelectedNetworkItem(0); } /////////////////////////////////////////////////////////////////////////////// @@ -140,7 +172,8 @@ void NetworkScreen::ConnectToNetwork(NetworkList::NetworkType type, const string16& id) { const NetworkList::NetworkItem* network = networks_.GetNetworkById(type, id); - if (network && !IsSameNetwork(network, networks_.ConnectedNetwork())) { + if (network && + !networks_.IsNetworkConnected(type, id)) { if (NetworkList::NETWORK_WIFI == network->network_type) { if (network->wifi_network.encrypted()) { OpenPasswordDialog(network->wifi_network); @@ -155,10 +188,6 @@ void NetworkScreen::ConnectToNetwork(NetworkList::NetworkType type, ConnectToCellularNetwork(network->cellular_network); } } - // Check if there's already connected network and update screen state. - MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod( - &NetworkScreen::NetworkChanged, - chromeos::CrosLibrary::Get()->GetNetworkLibrary())); } void NetworkScreen::SubscribeNetworkNotification() { @@ -179,25 +208,24 @@ NetworkList::NetworkItem* NetworkScreen::GetSelectedNetwork() { return networks_.GetNetworkAt(view()->GetSelectedNetworkItem() - 1); } -bool NetworkScreen::IsSameNetwork(const NetworkList::NetworkItem* network1, - const NetworkList::NetworkItem* network2) { - return (network1 && network2 && - network1->network_type == network2->network_type && - network1->label == network2->label); -} - void NetworkScreen::NotifyOnConnection() { + // TODO(nkostylev): Check network connectivity. UnsubscribeNetworkNotification(); + connection_timer_.Stop(); delegate()->GetObserver(this)->OnExit(ScreenObserver::NETWORK_CONNECTED); } -void NetworkScreen::NotifyOnOffline() { - UnsubscribeNetworkNotification(); - delegate()->GetObserver(this)->OnExit(ScreenObserver::NETWORK_OFFLINE); +void NetworkScreen::OnConnectionTimeout() { + // TODO(nkostylev): Notify on connection error. + if (is_waiting_for_connect_) { + // Stop waiting & show selection combobox. + StopWaitingForConnection(true); + } } void NetworkScreen::OpenPasswordDialog(WifiNetwork network) { NetworkConfigView* dialog = new NetworkConfigView(network, true); + dialog->set_delegate(this); dialog->set_browser_mode(false); views::Window* window = views::Window::CreateChromeWindow( view()->GetNativeWindow(), gfx::Rect(), dialog); @@ -216,4 +244,29 @@ void NetworkScreen::SelectNetwork(NetworkList::NetworkType type, } } +void NetworkScreen::StopWaitingForConnection(bool show_combobox) { + if (connection_timer_.IsRunning()) + connection_timer_.Stop(); + is_waiting_for_connect_ = false; + connecting_network_.network_type = NetworkList::NETWORK_EMPTY; + connecting_network_.label.clear(); + if (show_combobox) + view()->ShowConnectingStatus(is_waiting_for_connect_, + connecting_network_.label); +} + +void NetworkScreen::WaitForConnection(const NetworkList::NetworkItem* network) { + is_waiting_for_connect_ = true; + DCHECK(network); + connecting_network_.network_type = network->network_type; + connecting_network_.label = network->label; + if (connection_timer_.IsRunning()) + connection_timer_.Stop(); + connection_timer_.Start(base::TimeDelta::FromSeconds(kConnectionTimeoutSec), + this, + &NetworkScreen::OnConnectionTimeout); + view()->ShowConnectingStatus(is_waiting_for_connect_, + connecting_network_.label); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/network_screen.h b/chrome/browser/chromeos/login/network_screen.h index f7b0f24..68b7ec9 100644 --- a/chrome/browser/chromeos/login/network_screen.h +++ b/chrome/browser/chromeos/login/network_screen.h @@ -8,11 +8,13 @@ #include <string> #include "base/task.h" +#include "base/timer.h" #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/login/network_screen_delegate.h" #include "chrome/browser/chromeos/login/language_switch_model.h" #include "chrome/browser/chromeos/login/view_screen.h" #include "chrome/browser/chromeos/network_list.h" +#include "chrome/browser/chromeos/options/network_config_view.h" class WizardScreenDelegate; @@ -21,7 +23,8 @@ namespace chromeos { class NetworkSelectionView; class NetworkScreen : public ViewScreen<NetworkSelectionView>, - public NetworkScreenDelegate { + public NetworkScreenDelegate, + public NetworkConfigView::Delegate { public: NetworkScreen(WizardScreenDelegate* delegate, bool is_out_of_box); virtual ~NetworkScreen(); @@ -45,7 +48,10 @@ class NetworkScreen : public ViewScreen<NetworkSelectionView>, // NetworkLibrary::Observer implementation: virtual void NetworkChanged(NetworkLibrary* network_lib); - virtual void NetworkTraffic(NetworkLibrary* cros, int traffic_type); + virtual void NetworkTraffic(NetworkLibrary* cros, int traffic_type) {} + + // NetworkConfigView::Delegate implementation: + virtual void OnDialogCancelled(); protected: // Subscribes NetworkScreen to the network change notification, @@ -69,15 +75,11 @@ class NetworkScreen : public ViewScreen<NetworkSelectionView>, // Returns currently selected network in the combobox. NetworkList::NetworkItem* GetSelectedNetwork(); - // True if networks are the same. - bool IsSameNetwork(const NetworkList::NetworkItem* network1, - const NetworkList::NetworkItem* network2); - // Notifies wizard on successful connection. void NotifyOnConnection(); - // Notifies wizard when offline mode is selected. - void NotifyOnOffline(); + // Called by |connection_timer_| when connection to the network timed out. + void OnConnectionTimeout(); // Opens password dialog for the encrypted networks. void OpenPasswordDialog(WifiNetwork network); @@ -86,6 +88,13 @@ class NetworkScreen : public ViewScreen<NetworkSelectionView>, void SelectNetwork(NetworkList::NetworkType type, const string16& id); + // Stops waiting for network to connect. + // If |show_combobox| is false, spinner is left on screen. Used on exit. + void StopWaitingForConnection(bool show_combobox); + + // Starts waiting for network connection. Shows spinner. + void WaitForConnection(const NetworkList::NetworkItem* network); + // True if subscribed to network change notification. bool is_network_subscribed_; @@ -95,6 +104,18 @@ class NetworkScreen : public ViewScreen<NetworkSelectionView>, // True if full OOBE flow should be shown. bool is_out_of_box_; + // True if we're waiting for the selected network being connected. + bool is_waiting_for_connect_; + + // True if Ethernet was already preselected in combobox. + bool ethernet_preselected_; + + // Timer for connection timeout. + base::OneShotTimer<NetworkScreen> connection_timer_; + + // Network which we're connecting to. + NetworkList::NetworkItem connecting_network_; + ScopedRunnableMethodFactory<NetworkScreen> task_factory_; LanguageSwitchModel language_switch_model_; diff --git a/chrome/browser/chromeos/login/network_screen_browsertest.cc b/chrome/browser/chromeos/login/network_screen_browsertest.cc index 6d7203d..b7ba053 100644 --- a/chrome/browser/chromeos/login/network_screen_browsertest.cc +++ b/chrome/browser/chromeos/login/network_screen_browsertest.cc @@ -24,6 +24,7 @@ #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" +#include "views/controls/button/text_button.h" #include "views/controls/combobox/combobox.h" namespace chromeos { @@ -33,6 +34,22 @@ using ::testing::Return; using ::testing::ReturnRef; using ::testing::_; using ::testing::A; +using views::Button; + +class DummyButtonListener : public views::ButtonListener { + public: + virtual void ButtonPressed(views::Button* sender, + const views::Event& event) {} +}; + +class DummyComboboxModel : public ComboboxModel { + public: + virtual int GetItemCount() { return 2; } + + virtual std::wstring GetItemAt(int index) { + return L"Item " + IntToWString(index); + } +}; class NetworkScreenTest : public WizardInProcessBrowserTest { public: @@ -140,6 +157,23 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { .WillOnce((ReturnRef(name))); } + void EmulateContinueButtonExit(NetworkScreen* network_screen) { + scoped_ptr<MockScreenObserver> + mock_screen_observer(new MockScreenObserver()); + EXPECT_CALL(*mock_screen_observer, + OnExit(ScreenObserver::NETWORK_CONNECTED)) + .Times(1); + controller()->set_observer(mock_screen_observer.get()); + DummyButtonListener button_listener; + views::TextButton button(&button_listener, L"Button"); + views::MouseEvent event(views::Event::ET_MOUSE_RELEASED, + 0, 0, + views::Event::EF_LEFT_BUTTON_DOWN); + network_screen->ButtonPressed(&button, event); + ui_test_utils::RunAllPendingInMessageLoop(); + controller()->set_observer(NULL); + } + MockLoginLibrary* mock_login_library_; CellularNetworkVector cellular_networks_; @@ -152,15 +186,6 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { DISALLOW_COPY_AND_ASSIGN(NetworkScreenTest); }; -class DummyComboboxModel : public ComboboxModel { - public: - virtual int GetItemCount() { return 2; } - - virtual std::wstring GetItemAt(int index) { - return L"Item " + IntToWString(index); - } -}; - IN_PROC_BROWSER_TEST_F(NetworkScreenTest, Basic) { ASSERT_TRUE(controller()); NetworkScreen* network_screen = controller()->GetNetworkScreen(); @@ -186,8 +211,8 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, NetworksConnectedNotSelected) { EthernetExpectations(true, false); WifiCellularNetworksExpectations(); network_screen->NetworkChanged(network_library); - - // When OOBE flow is active network selection should be explicit. + // Ethernet is preselected once. + EXPECT_EQ(1, network_view->GetSelectedNetworkItem()); ASSERT_EQ(network_screen, controller()->current_screen()); ASSERT_EQ(2, network_screen->GetItemCount()); EXPECT_EQ(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET), @@ -222,6 +247,8 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, NetworksConnectedNotSelected) { network_screen->GetItemAt(1)); EXPECT_EQ(ASCIIToWide(wifi_.name()), network_screen->GetItemAt(2)); EXPECT_EQ(ASCIIToWide(cellular_.name()), network_screen->GetItemAt(3)); + // Ethernet is only preselected once. + EXPECT_EQ(0, network_view->GetSelectedNetworkItem()); } IN_PROC_BROWSER_TEST_F(NetworkScreenTest, EthernetSelected) { @@ -242,28 +269,24 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, EthernetSelected) { network_screen->GetItemAt(1)); ASSERT_EQ(network_screen, controller()->current_screen()); - // Emulate connected Ethernet. + // Emulate combobox selection - nothing happens. + 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()); + + // Emulate connected Ethernet - it should be preselected. EthernetExpectations(true, false); WifiCellularNetworksExpectations(); network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); + EXPECT_EQ(1, network_view->GetSelectedNetworkItem()); ASSERT_EQ(network_screen, controller()->current_screen()); - DummyComboboxModel combobox_model; - views::Combobox combobox(&combobox_model); - scoped_ptr<MockScreenObserver> mock_screen_observer(new MockScreenObserver()); - EXPECT_CALL(*mock_screen_observer, - OnExit(ScreenObserver::NETWORK_CONNECTED)) - .Times(1); - controller()->set_observer(mock_screen_observer.get()); - - // Emulate combobox selection. - EthernetExpectations(true, false); - WifiCellularNetworksExpectations(); - network_screen->ItemChanged(&combobox, 0, 1); - network_view->SetSelectedNetworkItem(1); - ui_test_utils::RunAllPendingInMessageLoop(); - controller()->set_observer(NULL); + // "Continue" button with connected network should proceed to next screen. + EmulateContinueButtonExit(network_screen); } IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiSelected) { @@ -297,6 +320,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiSelected) { string16())) .Times(1); ui_test_utils::RunAllPendingInMessageLoop(); + network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); // Emulate connecting to WiFi network. @@ -308,12 +332,6 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiSelected) { network_screen->NetworkChanged(network_library); ASSERT_EQ(network_screen, controller()->current_screen()); - scoped_ptr<MockScreenObserver> mock_screen_observer(new MockScreenObserver()); - EXPECT_CALL(*mock_screen_observer, - OnExit(ScreenObserver::NETWORK_CONNECTED)) - .Times(1); - controller()->set_observer(mock_screen_observer.get()); - // Emulate connected WiFi network. EthernetExpectations(false, false); SetupWifiNetwork(true, false); @@ -322,7 +340,10 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiSelected) { WifiSsidExpectation(wifi_.name()); network_screen->NetworkChanged(network_library); ui_test_utils::RunAllPendingInMessageLoop(); - controller()->set_observer(NULL); + ASSERT_EQ(network_screen, controller()->current_screen()); + + // "Continue" button with connected network should proceed to next screen. + EmulateContinueButtonExit(network_screen); } IN_PROC_BROWSER_TEST_F(NetworkScreenTest, CellularSelected) { @@ -354,6 +375,7 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, CellularSelected) { EXPECT_CALL(*mock_network_library_, ConnectToCellularNetwork(_)) .Times(1); ui_test_utils::RunAllPendingInMessageLoop(); + network_screen->NetworkChanged(network_library); ASSERT_EQ(2, network_screen->GetItemCount()); // Emulate connecting to cellular network. @@ -365,18 +387,82 @@ IN_PROC_BROWSER_TEST_F(NetworkScreenTest, CellularSelected) { network_screen->NetworkChanged(network_library); ASSERT_EQ(network_screen, controller()->current_screen()); - scoped_ptr<MockScreenObserver> mock_screen_observer(new MockScreenObserver()); + // Emulate connected cellular network. + EthernetExpectations(false, false); + SetupCellularNetwork(true, false); + CellularExpectations(true, false); + WifiCellularNetworksExpectations(); + CellularNameExpectation(cellular_.name()); + network_screen->NetworkChanged(network_library); + ui_test_utils::RunAllPendingInMessageLoop(); + ASSERT_EQ(network_screen, controller()->current_screen()); + + // "Continue" button with connected network should proceed to next screen. + EmulateContinueButtonExit(network_screen); +} + +IN_PROC_BROWSER_TEST_F(NetworkScreenTest, WifiWaiting) { + ASSERT_TRUE(controller()); + NetworkLibrary* network_library = + chromeos::CrosLibrary::Get()->GetNetworkLibrary(); + NetworkScreen* network_screen = controller()->GetNetworkScreen(); + ASSERT_TRUE(network_screen != NULL); + NetworkSelectionView* network_view = network_screen->view(); + ASSERT_TRUE(network_view != NULL); + + EthernetExpectations(false, false); + SetupWifiNetwork(false, false); + WifiCellularNetworksExpectations(); + WifiSsidExpectation(std::string()); + network_screen->NetworkChanged(network_library); + + DummyComboboxModel combobox_model; + views::Combobox combobox(&combobox_model); + + // Emulate combobox selection. + EthernetExpectations(false, false); + WifiCellularNetworksExpectations(); + WifiSsidExpectation(std::string()); + network_screen->ItemChanged(&combobox, 0, 1); + network_view->SetSelectedNetworkItem(1); + EXPECT_CALL(*mock_network_library_, + ConnectToWifiNetwork(A<WifiNetwork>(), string16(), string16(), + string16())) + .Times(1); + ui_test_utils::RunAllPendingInMessageLoop(); + network_screen->NetworkChanged(network_library); + ASSERT_EQ(2, network_screen->GetItemCount()); + + // Emulate connecting to WiFi network. + EthernetExpectations(false, false); + SetupWifiNetwork(false, true); + WifiExpectations(false, true); + WifiCellularNetworksExpectations(); + WifiSsidExpectation(wifi_.name()); + network_screen->NetworkChanged(network_library); + + // Continue but wait for connection. + scoped_ptr<MockScreenObserver> + mock_screen_observer(new MockScreenObserver()); EXPECT_CALL(*mock_screen_observer, OnExit(ScreenObserver::NETWORK_CONNECTED)) .Times(1); controller()->set_observer(mock_screen_observer.get()); + DummyButtonListener button_listener; + views::TextButton button(&button_listener, L"Button"); + views::MouseEvent event(views::Event::ET_MOUSE_RELEASED, + 0, 0, + views::Event::EF_LEFT_BUTTON_DOWN); + network_screen->ButtonPressed(&button, event); + ui_test_utils::RunAllPendingInMessageLoop(); + ASSERT_EQ(network_screen, controller()->current_screen()); - // Emulate connected cellular network. + // Emulate connected WiFi network. EthernetExpectations(false, false); - SetupCellularNetwork(true, false); - CellularExpectations(true, false); + SetupWifiNetwork(true, false); + WifiExpectations(true, false); WifiCellularNetworksExpectations(); - CellularNameExpectation(cellular_.name()); + WifiSsidExpectation(wifi_.name()); network_screen->NetworkChanged(network_library); ui_test_utils::RunAllPendingInMessageLoop(); controller()->set_observer(NULL); diff --git a/chrome/browser/chromeos/login/network_selection_view.cc b/chrome/browser/chromeos/login/network_selection_view.cc index 55a50b5..27f2321 100644 --- a/chrome/browser/chromeos/login/network_selection_view.cc +++ b/chrome/browser/chromeos/login/network_selection_view.cc @@ -37,7 +37,7 @@ using views::WidgetGtk; namespace { const int kWelcomeLabelY = 150; -const int kOfflineButtonX = 30; +const int kContinueButtonSpacingX = 30; const int kSpacing = 25; const int kHorizontalSpacing = 25; const int kNetworkComboboxWidth = 250; @@ -59,7 +59,7 @@ NetworkSelectionView::NetworkSelectionView(NetworkScreenDelegate* delegate) welcome_label_(NULL), select_network_label_(NULL), connecting_network_label_(NULL), - offline_button_(NULL), + continue_button_(NULL), throbber_(NULL), delegate_(delegate) { } @@ -101,27 +101,25 @@ void NetworkSelectionView::Init() { languages_menubutton_ = new views::MenuButton( NULL, std::wstring(), delegate_->language_switch_model(), true); - offline_button_ = new views::NativeButton(delegate_, std::wstring()); - AddChildView(welcome_label_); AddChildView(select_network_label_); AddChildView(connecting_network_label_); AddChildView(network_combobox_); AddChildView(languages_menubutton_); - AddChildView(offline_button_); UpdateLocalizedStrings(); } void NetworkSelectionView::UpdateLocalizedStrings() { + RecreateNativeControls(); languages_menubutton_->SetText( delegate_->language_switch_model()->GetCurrentLocaleName()); welcome_label_->SetText(l10n_util::GetStringF(IDS_NETWORK_SELECTION_TITLE, l10n_util::GetString(IDS_PRODUCT_OS_NAME))); select_network_label_->SetText( l10n_util::GetString(IDS_NETWORK_SELECTION_SELECT)); - offline_button_->SetLabel( - l10n_util::GetString(IDS_NETWORK_SELECTION_OFFLINE_BUTTON)); + continue_button_->SetLabel( + l10n_util::GetString(IDS_NETWORK_SELECTION_CONTINUE_BUTTON)); UpdateConnectingNetworkLabel(); } @@ -187,12 +185,13 @@ void NetworkSelectionView::Layout() { network_combobox_->SetBounds(select_network_x, y, kNetworkComboboxWidth, kNetworkComboboxHeight); - y = height() - offline_button_->GetPreferredSize().height() - kSpacing; - offline_button_->SetBounds( - kOfflineButtonX, + y = height() - continue_button_->GetPreferredSize().height() - kSpacing; + continue_button_->SetBounds( + width() - kContinueButtonSpacingX - + continue_button_->GetPreferredSize().width(), y, - offline_button_->GetPreferredSize().width(), - offline_button_->GetPreferredSize().height()); + continue_button_->GetPreferredSize().width(), + continue_button_->GetPreferredSize().height()); int x = width() - kLanguagesMenuWidth - kHorizontalSpacing; y = kSpacing; @@ -201,7 +200,7 @@ void NetworkSelectionView::Layout() { // Need to refresh combobox layout explicitly. network_combobox_->Layout(); - offline_button_->Layout(); + continue_button_->Layout(); } //////////////////////////////////////////////////////////////////////////////// @@ -238,9 +237,23 @@ void NetworkSelectionView::ShowConnectingStatus(bool connecting, } } +void NetworkSelectionView::EnableContinue(bool enabled) { + if (continue_button_) + continue_button_->SetEnabled(enabled); +} + //////////////////////////////////////////////////////////////////////////////// // NetworkSelectionView, private: +void NetworkSelectionView::RecreateNativeControls() { + // There is no way to get native button preferred size after the button was + // sized so delete and recreate the button on text update. + delete continue_button_; + continue_button_ = new views::NativeButton(delegate_, std::wstring()); + continue_button_->SetEnabled(false); + AddChildView(continue_button_); +} + void NetworkSelectionView::UpdateConnectingNetworkLabel() { connecting_network_label_->SetText(l10n_util::GetStringF( IDS_NETWORK_SELECTION_CONNECTING, UTF16ToWide(network_id_))); diff --git a/chrome/browser/chromeos/login/network_selection_view.h b/chrome/browser/chromeos/login/network_selection_view.h index ad52878..c72fd4f 100644 --- a/chrome/browser/chromeos/login/network_selection_view.h +++ b/chrome/browser/chromeos/login/network_selection_view.h @@ -52,12 +52,19 @@ class NetworkSelectionView : public views::View { // Shows network connecting status or network selection otherwise. void ShowConnectingStatus(bool connecting, const string16& network_id); + // Sets whether continue control is enabled. + void EnableContinue(bool enabled); + protected: // Overridden from views::View. virtual void ChildPreferredSizeChanged(View* child); virtual void LocaleChanged(); private: + // Delete and recreate native controls that + // fail to update preferred size after string update. + void RecreateNativeControls(); + // Updates text on label with currently connecting network. void UpdateConnectingNetworkLabel(); @@ -67,7 +74,7 @@ class NetworkSelectionView : public views::View { views::Label* welcome_label_; views::Label* select_network_label_; views::Label* connecting_network_label_; - views::NativeButton* offline_button_; + views::NativeButton* continue_button_; views::SmoothedThrobber* throbber_; // NetworkScreen delegate. diff --git a/chrome/browser/chromeos/network_list.cc b/chrome/browser/chromeos/network_list.cc index cea21ce..f92190f 100644 --- a/chrome/browser/chromeos/network_list.cc +++ b/chrome/browser/chromeos/network_list.cc @@ -11,9 +11,10 @@ namespace chromeos { -NetworkList::NetworkList() - : connected_network_index_(-1), - connecting_network_index_(-1) { +//////////////////////////////////////////////////////////////////////////////// +// NetworkList, public: + +NetworkList::NetworkList() { } NetworkList::NetworkItem* NetworkList::GetNetworkAt(int index) { @@ -21,66 +22,39 @@ NetworkList::NetworkItem* NetworkList::GetNetworkAt(int index) { &networks_[index] : NULL; } -const NetworkList::NetworkItem* NetworkList::GetNetworkById(NetworkType type, - const string16& id) { +const NetworkList::NetworkItem* NetworkList::GetNetworkById( + NetworkType type, const string16& id) { return GetNetworkAt(GetNetworkIndexById(type, id)); } int NetworkList::GetNetworkIndexById(NetworkType type, const string16& id) const { - if (NETWORK_EMPTY == type || id.empty()) return -1; + if (type == NETWORK_EMPTY) + return -1; std::string network_id = UTF16ToASCII(id); - for (size_t i = 0; i < networks_.size(); i++) { - if (type == networks_[i].network_type) { - switch (type) { - case NETWORK_ETHERNET: - // Assuming that there's only single Ethernet network. - return i; - - case NETWORK_WIFI: - if (network_id == networks_[i].wifi_network.name()) - return i; - break; - - case NETWORK_CELLULAR: - if (network_id == networks_[i].cellular_network.name()) - return i; - break; - - default: - break; - } - } + for (size_t i = 0; i < networks_.size(); ++i) { + if (IsSameNetwork(&networks_[i], type, network_id)) + return i; } return -1; } -// Returns currently connected network if there is one. -const NetworkList::NetworkItem* NetworkList::ConnectedNetwork() const { - if (connected_network_index_ >= 0 && - connected_network_index_ < static_cast<int>(networks_.size())) { - return &networks_[connected_network_index_]; - } else { - return NULL; - } +bool NetworkList::IsNetworkConnected(NetworkType type, + const string16& id) const { + return IsInNetworkList(connected_networks_, type, id); } -// Returns currently connecting network if there is one. -const NetworkList::NetworkItem* NetworkList::ConnectingNetwork() const { - if (connecting_network_index_ >= 0 && - connecting_network_index_ < static_cast<int>(networks_.size())) { - return &networks_[connecting_network_index_]; - } else { - return NULL; - } +bool NetworkList::IsNetworkConnecting(NetworkType type, + const string16& id) const { + return IsInNetworkList(connecting_networks_, type, id); } void NetworkList::NetworkChanged(chromeos::NetworkLibrary* network_lib) { - connected_network_index_ = -1; - connecting_network_index_ = -1; networks_.clear(); + connected_networks_.clear(); + connecting_networks_.clear(); // Index of the last added network item. - int index = 0; + size_t index = 0; if (!network_lib || !CrosLibrary::Get()->EnsureLoaded()) return; @@ -93,7 +67,7 @@ void NetworkList::NetworkChanged(chromeos::NetworkLibrary* network_lib) { label, WifiNetwork(), CellularNetwork())); - SetNetworksIndices(index++, ethernet_connected, ethernet_connecting); + AddNetworkIndexToList(index++, ethernet_connected, ethernet_connecting); } // TODO(nkostylev): Show public WiFi networks first. @@ -105,9 +79,9 @@ void NetworkList::NetworkChanged(chromeos::NetworkLibrary* network_lib) { *it, CellularNetwork())); if (network_lib->wifi_name() == it->name()) { - SetNetworksIndices(index, - network_lib->wifi_connected(), - network_lib->wifi_connecting()); + AddNetworkIndexToList(index, + network_lib->wifi_connected(), + network_lib->wifi_connecting()); } } @@ -119,25 +93,57 @@ void NetworkList::NetworkChanged(chromeos::NetworkLibrary* network_lib) { WifiNetwork(), *it)); if (network_lib->cellular_name() == it->name()) { - SetNetworksIndices(index, - network_lib->cellular_connected(), - network_lib->cellular_connecting()); + AddNetworkIndexToList(index, + network_lib->cellular_connected(), + network_lib->cellular_connecting()); } } } -void NetworkList::SetNetworksIndices(int index, - bool connected, - bool connecting) { - if (connected_network_index_ != -1 || - connecting_network_index_ != -1 || - index < 0 || index >= static_cast<int>(networks_.size())) - return; +//////////////////////////////////////////////////////////////////////////////// +// NetworkList, private: + +bool NetworkList::IsInNetworkList(const NetworkIndexVector& list, + NetworkType type, + const string16& id) const { + if (type == NETWORK_EMPTY) + return false; + std::string network_id = UTF16ToASCII(id); + for (size_t i = 0; i < list.size(); ++i) { + if (IsSameNetwork(&networks_[list[i]], type, network_id)) + return true; + } + return false; +} + +bool NetworkList::IsSameNetwork(const NetworkList::NetworkItem* network, + NetworkType type, + const std::string& id) const { + if (type != network->network_type) + return false; + switch (type) { + case NETWORK_ETHERNET: + // Assuming that there's only single Ethernet network. + return true; + case NETWORK_WIFI: + return id == network->wifi_network.name(); + break; + case NETWORK_CELLULAR: + return id == network->cellular_network.name(); + break; + default: + return false; + break; + } +} +void NetworkList::AddNetworkIndexToList(size_t index, + bool connected, + bool connecting) { if (connected) { - connected_network_index_ = index; + connected_networks_.push_back(index); } else if (connecting) { - connecting_network_index_ = index; + connecting_networks_.push_back(index); } } diff --git a/chrome/browser/chromeos/network_list.h b/chrome/browser/chromeos/network_list.h index 2995f80..f08b23a 100644 --- a/chrome/browser/chromeos/network_list.h +++ b/chrome/browser/chromeos/network_list.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_LIST_H_ #define CHROME_BROWSER_CHROMEOS_NETWORK_LIST_H_ +#include <string> #include <vector> #include "chrome/browser/chromeos/cros/network_library.h" @@ -28,6 +29,10 @@ class NetworkList { : network_type(NETWORK_EMPTY), connected(false) {} NetworkItem(NetworkType network_type, + const string16& label) + : network_type(network_type), + label(label) {} + NetworkItem(NetworkType network_type, string16 label, WifiNetwork wifi_network, CellularNetwork cellular_network) @@ -52,11 +57,11 @@ class NetworkList { return networks_.empty(); } - // Returns currently connected network if there is one. - const NetworkList::NetworkItem* ConnectedNetwork() const; + // Returns true, if specified network is currently connected. + bool IsNetworkConnected(NetworkType type, const string16& id) const; - // Returns currently connecting network if there is one. - const NetworkList::NetworkItem* ConnectingNetwork() const; + // Returns true, if specified network is currently connected. + bool IsNetworkConnecting(NetworkType type, const string16& id) const; // Returns network by it's type and ssid (Wifi) or id (Cellular). // If network is not available NULL is returned. @@ -80,21 +85,30 @@ class NetworkList { private: typedef std::vector<NetworkItem> NetworkItemVector; + typedef std::vector<size_t> NetworkIndexVector; + + // Returns true if the specified network is in the list. + bool IsInNetworkList(const NetworkIndexVector& list, + NetworkType type, + const string16& id) const; + + // Returns true if network is of the same type and id. + bool IsSameNetwork(const NetworkList::NetworkItem* network, + NetworkType type, + const std::string& id) const; - // Set connected/connecting network indices. - // index - network index being processed - void SetNetworksIndices(int index, bool connected, bool connecting); + // Adds network index to the corresponding connected/connecting network list. + // |index| - network index being processed + void AddNetworkIndexToList(size_t index, bool connected, bool connecting); - // Cached list of all available networks. + // Cached list of all available networks with their connection states. NetworkItemVector networks_; - // Index of currently connected network or -1 if there's none. - // If several networks are connected than single one is selected by priority: - // Ethernet > WiFi > Cellular. - int connected_network_index_; + // Connected networks indexes. + NetworkIndexVector connected_networks_; - // Index of currently connecting network or -1 if there's none. - int connecting_network_index_; + // Connecting networks indexes. + NetworkIndexVector connecting_networks_; DISALLOW_COPY_AND_ASSIGN(NetworkList); }; diff --git a/chrome/browser/chromeos/options/network_config_view.cc b/chrome/browser/chromeos/options/network_config_view.cc index f5aa05e..e3ea604 100644 --- a/chrome/browser/chromeos/options/network_config_view.cc +++ b/chrome/browser/chromeos/options/network_config_view.cc @@ -25,7 +25,8 @@ NetworkConfigView::NetworkConfigView(EthernetNetwork ethernet) flags_(FLAG_ETHERNET | FLAG_SHOW_IPCONFIG), ethernet_(ethernet), wificonfig_view_(NULL), - ipconfig_view_(NULL) { + ipconfig_view_(NULL), + delegate_(NULL) { } NetworkConfigView::NetworkConfigView(WifiNetwork wifi, bool login_only) @@ -33,7 +34,8 @@ NetworkConfigView::NetworkConfigView(WifiNetwork wifi, bool login_only) flags_(FLAG_WIFI), wifi_(wifi), wificonfig_view_(NULL), - ipconfig_view_(NULL) { + ipconfig_view_(NULL), + delegate_(NULL) { if (login_only) flags_ |= FLAG_LOGIN_ONLY; else @@ -45,14 +47,16 @@ NetworkConfigView::NetworkConfigView(CellularNetwork cellular) flags_(FLAG_CELLULAR | FLAG_SHOW_IPCONFIG), cellular_(cellular), wificonfig_view_(NULL), - ipconfig_view_(NULL) { + ipconfig_view_(NULL), + delegate_(NULL) { } NetworkConfigView::NetworkConfigView() : browser_mode_(true), flags_(FLAG_WIFI | FLAG_LOGIN_ONLY | FLAG_OTHER_NETWORK), wificonfig_view_(NULL), - ipconfig_view_(NULL) { + ipconfig_view_(NULL), + delegate_(NULL) { } gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { @@ -79,6 +83,8 @@ bool NetworkConfigView::IsDialogButtonEnabled( } bool NetworkConfigView::Cancel() { + if (delegate_) + delegate_->OnDialogCancelled(); return true; } diff --git a/chrome/browser/chromeos/options/network_config_view.h b/chrome/browser/chromeos/options/network_config_view.h index 3b42abd..6a2653e 100644 --- a/chrome/browser/chromeos/options/network_config_view.h +++ b/chrome/browser/chromeos/options/network_config_view.h @@ -28,6 +28,14 @@ class NetworkConfigView : public views::View, public views::DialogDelegate, views::TabbedPane::Listener { public: + class Delegate { + public: + // Called when dialog "Cancel" button is pressed. + virtual void OnDialogCancelled() = 0; + protected: + virtual ~Delegate() {} + }; + // Configure dialog for ethernet. explicit NetworkConfigView(EthernetNetwork ethernet); // Configure dialog for wifi. If |login_only|, then only show login tab. @@ -70,6 +78,10 @@ class NetworkConfigView : public views::View, return browser_mode_; } + void set_delegate(Delegate* delegate) { + delegate_ = delegate; + } + protected: // views::View overrides: virtual void Layout(); @@ -106,6 +118,8 @@ class NetworkConfigView : public views::View, WifiConfigView* wificonfig_view_; IPConfigView* ipconfig_view_; + Delegate* delegate_; + DISALLOW_COPY_AND_ASSIGN(NetworkConfigView); }; |