Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/network/network_state.h" | 5 #include "chromeos/network/network_state.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class TestStringValue : public base::Value { | 18 class TestStringValue : public base::Value { |
|
pneubeck (no reviews)
2013/07/29 19:13:25
Because I stumbled over this before and needs a lo
stevenjb
2013/07/29 20:25:47
This code predates https://chromiumcodereview.apps
| |
| 19 public: | 19 public: |
| 20 explicit TestStringValue(const std::string& in_value) | 20 explicit TestStringValue(const std::string& in_value) |
| 21 : base::Value(TYPE_STRING), | 21 : base::Value(TYPE_STRING), |
| 22 value_(in_value) { | 22 value_(in_value) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 virtual ~TestStringValue() { | 25 virtual ~TestStringValue() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 // Overridden from Value: | 28 // Overridden from Value: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 47 std::string value_; | 47 std::string value_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class NetworkStateTest : public testing::Test { | 50 class NetworkStateTest : public testing::Test { |
| 51 public: | 51 public: |
| 52 NetworkStateTest() : network_state_("test_path") { | 52 NetworkStateTest() : network_state_("test_path") { |
| 53 } | 53 } |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 bool SetStringProperty(const std::string& key, const std::string& value) { | 56 bool SetStringProperty(const std::string& key, const std::string& value) { |
| 57 if (!network_state_.PropertyChanged(key, TestStringValue(value))) | 57 bool res = network_state_.PropertyChanged(key, TestStringValue(value)); |
| 58 return false; | 58 properties_.SetStringWithoutPathExpansion(key, value); |
| 59 network_state_.InitialPropertiesReceived(); | 59 return res; |
| 60 return true; | 60 } |
| 61 | |
| 62 void SignalInitialPropertiesReceived() { | |
|
pneubeck (no reviews)
2013/07/29 19:13:25
If InitialPropertiesReceived returns a bool, then
stevenjb
2013/07/29 20:25:47
Done.
| |
| 63 network_state_.InitialPropertiesReceived(properties_); | |
| 61 } | 64 } |
| 62 | 65 |
| 63 NetworkState network_state_; | 66 NetworkState network_state_; |
| 64 | 67 |
| 65 private: | 68 private: |
| 69 base::DictionaryValue properties_; | |
| 70 | |
| 66 DISALLOW_COPY_AND_ASSIGN(NetworkStateTest); | 71 DISALLOW_COPY_AND_ASSIGN(NetworkStateTest); |
| 67 }; | 72 }; |
| 68 | 73 |
| 69 } // namespace | 74 } // namespace |
| 70 | 75 |
| 71 // Seting kNameProperty should set network name after call to | 76 // Seting kNameProperty should set network name after call to |
| 72 // InitialPropertiesReceived() in SetStringProperty(). | 77 // InitialPropertiesReceived() in SetStringProperty(). |
| 73 TEST_F(NetworkStateTest, SsidAscii) { | 78 TEST_F(NetworkStateTest, SsidAscii) { |
| 74 std::string wifi_setname = "SSID TEST"; | 79 std::string wifi_setname = "SSID TEST"; |
| 75 std::string wifi_setname_result = "SSID TEST"; | 80 std::string wifi_setname_result = "SSID TEST"; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 90 std::string wifi_utf8_result = "UTF-8 \xE3\x81\x82\xE3\x81\x84\xE3\x81\x86"; | 95 std::string wifi_utf8_result = "UTF-8 \xE3\x81\x82\xE3\x81\x84\xE3\x81\x86"; |
| 91 EXPECT_TRUE(SetStringProperty(flimflam::kNameProperty, wifi_utf8)); | 96 EXPECT_TRUE(SetStringProperty(flimflam::kNameProperty, wifi_utf8)); |
| 92 EXPECT_EQ(network_state_.name(), wifi_utf8_result); | 97 EXPECT_EQ(network_state_.name(), wifi_utf8_result); |
| 93 } | 98 } |
| 94 | 99 |
| 95 // Truncates invalid UTF-8 | 100 // Truncates invalid UTF-8 |
| 96 TEST_F(NetworkStateTest, SsidTruncateInvalid) { | 101 TEST_F(NetworkStateTest, SsidTruncateInvalid) { |
| 97 std::string wifi_setname2 = "SSID TEST \x01\xff!"; | 102 std::string wifi_setname2 = "SSID TEST \x01\xff!"; |
| 98 std::string wifi_setname2_result = "SSID TEST \xEF\xBF\xBD\xEF\xBF\xBD!"; | 103 std::string wifi_setname2_result = "SSID TEST \xEF\xBF\xBD\xEF\xBF\xBD!"; |
| 99 EXPECT_TRUE(SetStringProperty(flimflam::kNameProperty, wifi_setname2)); | 104 EXPECT_TRUE(SetStringProperty(flimflam::kNameProperty, wifi_setname2)); |
| 105 SignalInitialPropertiesReceived(); | |
| 100 EXPECT_EQ(network_state_.name(), wifi_setname2_result); | 106 EXPECT_EQ(network_state_.name(), wifi_setname2_result); |
| 101 } | 107 } |
| 102 | 108 |
| 103 // latin1 SSID -> UTF8 SSID (Hex) | 109 // latin1 SSID -> UTF8 SSID (Hex) |
| 104 TEST_F(NetworkStateTest, SsidLatin) { | 110 TEST_F(NetworkStateTest, SsidLatin) { |
| 105 std::string wifi_latin1 = "latin-1 \xc0\xcb\xcc\xd6\xfb"; | 111 std::string wifi_latin1 = "latin-1 \xc0\xcb\xcc\xd6\xfb"; |
| 106 std::string wifi_latin1_hex = | 112 std::string wifi_latin1_hex = |
| 107 base::HexEncode(wifi_latin1.c_str(), wifi_latin1.length()); | 113 base::HexEncode(wifi_latin1.c_str(), wifi_latin1.length()); |
| 108 std::string wifi_latin1_result = "latin-1 \u00c0\u00cb\u00cc\u00d6\u00fb"; | 114 std::string wifi_latin1_result = "latin-1 \u00c0\u00cb\u00cc\u00d6\u00fb"; |
| 109 EXPECT_TRUE(SetStringProperty(flimflam::kWifiHexSsid, wifi_latin1_hex)); | 115 SetStringProperty(flimflam::kWifiHexSsid, wifi_latin1_hex); |
| 116 SignalInitialPropertiesReceived(); | |
| 110 EXPECT_EQ(network_state_.name(), wifi_latin1_result); | 117 EXPECT_EQ(network_state_.name(), wifi_latin1_result); |
| 111 } | 118 } |
| 112 | 119 |
| 113 // Hex SSID | 120 // Hex SSID |
| 114 TEST_F(NetworkStateTest, SsidHex) { | 121 TEST_F(NetworkStateTest, SsidHex) { |
| 115 std::string wifi_hex = "5468697320697320484558205353494421"; | 122 std::string wifi_hex = "5468697320697320484558205353494421"; |
| 116 std::string wifi_hex_result = "This is HEX SSID!"; | 123 std::string wifi_hex_result = "This is HEX SSID!"; |
| 117 SetStringProperty(flimflam::kWifiHexSsid, wifi_hex); | 124 SetStringProperty(flimflam::kWifiHexSsid, wifi_hex); |
| 125 SignalInitialPropertiesReceived(); | |
| 118 EXPECT_EQ(network_state_.name(), wifi_hex_result); | 126 EXPECT_EQ(network_state_.name(), wifi_hex_result); |
| 119 } | 127 } |
| 120 | 128 |
| 121 } // namespace chromeos | 129 } // namespace chromeos |
| OLD | NEW |