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