OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/strings/string_number_conversions.h" | |
7 #include "content/public/common/content_switches.h" | 8 #include "content/public/common/content_switches.h" |
8 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
9 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
10 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
11 #include "content/shell/browser/shell.h" | 12 #include "content/shell/browser/shell.h" |
12 #include "net/base/network_change_notifier.h" | 13 #include "net/base/network_change_notifier.h" |
13 #include "net/base/network_change_notifier_factory.h" | 14 #include "net/base/network_change_notifier_factory.h" |
14 | 15 |
16 namespace content { | |
17 | |
18 using net::NetworkChangeNotifier; | |
19 | |
15 class NetInfoBrowserTest : public content::ContentBrowserTest { | 20 class NetInfoBrowserTest : public content::ContentBrowserTest { |
16 protected: | 21 protected: |
17 void SetUpCommandLine(base::CommandLine* command_line) override { | 22 void SetUpCommandLine(base::CommandLine* command_line) override { |
18 // TODO(jkarlin): Once NetInfo is enabled on all platforms remove this | 23 // TODO(jkarlin): Once NetInfo is enabled on all platforms remove this |
19 // switch. | 24 // switch. |
20 command_line->AppendSwitch(switches::kEnableNetworkInformation); | 25 command_line->AppendSwitch(switches::kEnableNetworkInformation); |
26 | |
27 // TODO(jkarlin): Remove this once downlinkMax is no longer | |
28 // experimental. | |
29 command_line->AppendSwitch( | |
30 switches::kEnableExperimentalWebPlatformFeatures); | |
21 } | 31 } |
22 | 32 |
23 void SetUp() override { | 33 void SetUp() override { |
24 net::NetworkChangeNotifier::SetTestNotificationsOnly(true); | 34 NetworkChangeNotifier::SetTestNotificationsOnly(true); |
25 | 35 |
26 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
27 // ChromeOS's NetworkChangeNotifier isn't known to content and therefore | 37 // ChromeOS's NetworkChangeNotifier isn't known to content and therefore |
28 // doesn't get created in content_browsertests. Insert a mock | 38 // doesn't get created in content_browsertests. Insert a mock |
29 // NetworkChangeNotifier. | 39 // NetworkChangeNotifier. |
30 net::NetworkChangeNotifier::CreateMock(); | 40 NetworkChangeNotifier::CreateMock(); |
31 #endif | 41 #endif |
32 | 42 |
33 content::ContentBrowserTest::SetUp(); | 43 content::ContentBrowserTest::SetUp(); |
34 } | 44 } |
35 | 45 |
36 void SetUpOnMainThread() override { | 46 void SetUpOnMainThread() override { |
37 base::RunLoop().RunUntilIdle(); | 47 base::RunLoop().RunUntilIdle(); |
38 } | 48 } |
39 | 49 |
40 static void SetConnectionType( | 50 static void SetConnectionType( |
41 net::NetworkChangeNotifier::ConnectionType type) { | 51 NetworkChangeNotifier::ConnectionType type, |
42 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests( | 52 NetworkChangeNotifier::ConnectionSubtype subtype) { |
43 type); | 53 NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChangeForTests( |
54 type, GetMaxBandwidthForSubtype(subtype)); | |
44 base::RunLoop().RunUntilIdle(); | 55 base::RunLoop().RunUntilIdle(); |
45 } | 56 } |
46 | 57 |
58 static double GetMaxBandwidthForSubtype( | |
59 NetworkChangeNotifier::ConnectionSubtype subtype) { | |
60 return NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype(subtype); | |
61 } | |
pauljensen
2015/09/11 14:25:37
Now that you unprotected NCN::GetMaxBandwidthForCo
jkarlin
2015/09/11 20:15:21
Done.
| |
62 | |
47 std::string RunScriptExtractString(const std::string& script) { | 63 std::string RunScriptExtractString(const std::string& script) { |
48 std::string data; | 64 std::string data; |
49 EXPECT_TRUE( | 65 EXPECT_TRUE( |
50 ExecuteScriptAndExtractString(shell()->web_contents(), script, &data)); | 66 ExecuteScriptAndExtractString(shell()->web_contents(), script, &data)); |
51 return data; | 67 return data; |
52 } | 68 } |
53 | 69 |
54 bool RunScriptExtractBool(const std::string& script) { | 70 bool RunScriptExtractBool(const std::string& script) { |
55 bool data; | 71 bool data; |
56 EXPECT_TRUE( | 72 EXPECT_TRUE( |
57 ExecuteScriptAndExtractBool(shell()->web_contents(), script, &data)); | 73 ExecuteScriptAndExtractBool(shell()->web_contents(), script, &data)); |
58 return data; | 74 return data; |
59 } | 75 } |
76 | |
77 double RunScriptExtractDouble(const std::string& script) { | |
78 double data = 0.0; | |
79 EXPECT_TRUE(base::StringToDouble(RunScriptExtractString(script), &data)); | |
80 return data; | |
81 } | |
60 }; | 82 }; |
61 | 83 |
62 // Make sure that type changes in the browser make their way to | 84 // Make sure that type changes in the browser make their way to |
63 // navigator.connection.type. | 85 // navigator.connection.type. |
64 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkChangePlumbsToNavigator) { | 86 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkChangePlumbsToNavigator) { |
65 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html")); | 87 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html")); |
66 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); | 88 SetConnectionType(NetworkChangeNotifier::CONNECTION_WIFI, |
89 NetworkChangeNotifier::SUBTYPE_WIFI_N); | |
67 EXPECT_EQ("wifi", RunScriptExtractString("getType()")); | 90 EXPECT_EQ("wifi", RunScriptExtractString("getType()")); |
68 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 91 EXPECT_EQ(GetMaxBandwidthForSubtype(NetworkChangeNotifier::SUBTYPE_WIFI_N), |
92 RunScriptExtractDouble("getDownlinkMax()")); | |
93 | |
94 SetConnectionType(NetworkChangeNotifier::CONNECTION_ETHERNET, | |
95 NetworkChangeNotifier::SUBTYPE_GIGABIT_ETHERNET); | |
69 EXPECT_EQ("ethernet", RunScriptExtractString("getType()")); | 96 EXPECT_EQ("ethernet", RunScriptExtractString("getType()")); |
97 EXPECT_EQ(GetMaxBandwidthForSubtype( | |
98 NetworkChangeNotifier::SUBTYPE_GIGABIT_ETHERNET), | |
99 RunScriptExtractDouble("getDownlinkMax()")); | |
70 } | 100 } |
71 | 101 |
72 // Make sure that type changes in the browser make their way to | 102 // Make sure that type changes in the browser make their way to |
73 // navigator.isOnline. | 103 // navigator.isOnline. |
74 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, IsOnline) { | 104 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, IsOnline) { |
75 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html")); | 105 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html")); |
76 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | 106 SetConnectionType(NetworkChangeNotifier::CONNECTION_ETHERNET, |
107 NetworkChangeNotifier::SUBTYPE_GIGABIT_ETHERNET); | |
77 EXPECT_TRUE(RunScriptExtractBool("getOnLine()")); | 108 EXPECT_TRUE(RunScriptExtractBool("getOnLine()")); |
78 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE); | 109 SetConnectionType(NetworkChangeNotifier::CONNECTION_NONE, |
110 NetworkChangeNotifier::SUBTYPE_NONE); | |
79 EXPECT_FALSE(RunScriptExtractBool("getOnLine()")); | 111 EXPECT_FALSE(RunScriptExtractBool("getOnLine()")); |
80 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_WIFI); | 112 SetConnectionType(NetworkChangeNotifier::CONNECTION_WIFI, |
113 NetworkChangeNotifier::SUBTYPE_WIFI_N); | |
81 EXPECT_TRUE(RunScriptExtractBool("getOnLine()")); | 114 EXPECT_TRUE(RunScriptExtractBool("getOnLine()")); |
82 } | 115 } |
116 | |
117 } // namespace content | |
OLD | NEW |