OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/shell.h" | |
6 #include "ash/system/cast/tray_cast.h" | |
7 #include "ash/system/tray/system_tray.h" | |
8 #include "ash/system/tray/system_tray_delegate.h" | |
9 #include "ash/system/tray/system_tray_item.h" | |
10 #include "chrome/browser/extensions/extension_browsertest.h" | |
11 #include "chrome/browser/profiles/profile_manager.h" | |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
13 #include "content/public/browser/render_view_host.h" | |
14 #include "content/public/test/test_utils.h" | |
15 #include "extensions/browser/process_manager.h" | |
16 | |
17 namespace chromeos { | |
18 | |
achuithb
2015/07/08 22:04:55
remove newline
jdufault
2015/07/09 23:12:56
Done.
| |
19 namespace { | |
20 | |
21 // Execute JavaScript within the context of the extension. Returns the result | |
22 // of the execution. | |
23 scoped_ptr<base::Value> ExecuteJavaScript( | |
24 const extensions::Extension* extension, | |
25 const std::string& javascript) { | |
26 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
27 if (!profile) { | |
28 LOG(ERROR) << "Expected profile"; | |
29 return nullptr; | |
30 } | |
31 | |
32 extensions::ProcessManager* pm = extensions::ProcessManager::Get(profile); | |
achuithb
2015/07/08 22:04:55
You could use auto here
jdufault
2015/07/09 23:12:57
Done.
| |
33 auto host = | |
achuithb
2015/07/08 22:04:55
Don't think this is appropriate since the type is
jdufault
2015/07/09 23:12:58
Done.
| |
34 pm->GetBackgroundHostForExtension(extension->id())->render_view_host(); | |
35 return content::ExecuteScriptAndGetValue(host->GetMainFrame(), javascript); | |
36 } | |
37 | |
38 // Ensures that all pending JavaScript execution callbacks are invoked. | |
39 void ExecutePendingJavaScript(const extensions::Extension* extension) { | |
40 ExecuteJavaScript(extension, ""); | |
41 } | |
42 | |
43 // Returns the cast tray. The tray initializer may have launched some | |
44 // JavaScript callbacks which have not finished executing. | |
45 ash::TrayCast* GetTrayCast() { | |
46 ash::Shell::GetInstance()->GetPrimarySystemTray()->ShowDefaultView( | |
achuithb
2015/07/08 22:04:55
I think it's worthwhile to create a temporary for
jdufault
2015/07/09 23:12:57
Done.
| |
47 ash::BubbleCreationType::BUBBLE_CREATE_NEW); | |
achuithb
2015/07/08 22:04:55
What's going on here?
jdufault
2015/07/09 23:12:57
I've added a comment.
| |
48 return ash::Shell::GetInstance() | |
49 ->GetPrimarySystemTray() | |
50 ->GetTrayCastForTesting(); | |
51 } | |
52 | |
53 } // namespace | |
54 | |
55 class SystemTrayTrayCastChromeOSTest : public ExtensionBrowserTest { | |
56 protected: | |
57 SystemTrayTrayCastChromeOSTest() : ExtensionBrowserTest() {} | |
58 | |
achuithb
2015/07/08 22:04:55
remove newline?
jdufault
2015/07/09 23:12:57
Done.
| |
59 ~SystemTrayTrayCastChromeOSTest() override {} | |
60 | |
61 const extensions::Extension* LoadCastTestExtension() { | |
62 return LoadExtension(test_data_dir_.AppendASCII("tray_cast")); | |
63 } | |
64 | |
65 private: | |
66 DISALLOW_COPY_AND_ASSIGN(SystemTrayTrayCastChromeOSTest); | |
67 }; | |
68 | |
69 // A simple sanity check to make sure that the cast config delegate actually | |
70 // recongnizes the cast extension. | |
achuithb
2015/07/08 22:04:55
sp recognizes
jdufault
2015/07/09 23:12:57
Done.
| |
71 IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, | |
72 CastTraySanityCheckTestExtensionGetsRecognized) { | |
73 auto cast_config_delegate = ash::Shell::GetInstance() | |
achuithb
2015/07/08 22:04:55
Type is not clear
jdufault
2015/07/09 23:12:57
Done.
| |
74 ->system_tray_delegate() | |
75 ->GetCastConfigDelegate(); | |
76 | |
77 EXPECT_FALSE(cast_config_delegate->HasCastExtension()); | |
78 LoadCastTestExtension(); | |
79 EXPECT_TRUE(cast_config_delegate->HasCastExtension()); | |
80 } | |
81 | |
82 // Verifies that the cast tray is hidden when there is no extension installed. | |
83 IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, | |
84 CastTrayIsHiddenWhenThereIsNoExtension) { | |
85 ash::TrayCast* tray = GetTrayCast(); | |
86 EXPECT_TRUE(tray->IsTrayInitializedForTest()); | |
87 EXPECT_FALSE(tray->IsTrayVisibleForTest()); | |
88 } | |
89 | |
90 // Verifies that the cast tray is hidden if there are no available receivers, | |
91 // even if there is an extension installed. | |
92 IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, | |
93 CastTrayIsHiddenWhenThereIsAnExtensionButNoReceivers) { | |
94 auto extension = LoadCastTestExtension(); | |
achuithb
2015/07/08 22:04:55
Type is not clear
jdufault
2015/07/09 23:12:57
Done.
| |
95 | |
96 ash::TrayCast* tray = GetTrayCast(); | |
97 ExecutePendingJavaScript(extension); | |
98 | |
99 EXPECT_TRUE(tray->IsTrayInitializedForTest()); | |
100 EXPECT_FALSE(tray->IsTrayVisibleForTest()); | |
101 } | |
102 | |
103 // Verifies that the cast tray is displayed when there are receivers available. | |
104 IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, | |
105 CastTrayIsDisplayedWhenThereIsAnExtensionWithReceivers) { | |
106 auto extension = LoadCastTestExtension(); | |
achuithb
2015/07/08 22:04:55
Type is not clear.
jdufault
2015/07/09 23:12:57
Done.
| |
107 ExecuteJavaScript(extension, "addReceiver('id', 'name', 'title', 1)"); | |
achuithb
2015/07/08 22:04:55
test_id?
jdufault
2015/07/09 23:12:57
Done.
| |
108 | |
109 ash::TrayCast* tray = GetTrayCast(); | |
110 ExecutePendingJavaScript(extension); | |
achuithb
2015/07/08 22:04:55
I don't understand the rationale for this sequence
jdufault
2015/07/09 23:12:57
I've modified GetTrayCast so it takes an extension
achuithb
2015/07/10 21:32:06
Yup, I like that better
| |
111 | |
112 EXPECT_TRUE(tray->IsTrayInitializedForTest()); | |
113 EXPECT_TRUE(tray->IsTrayVisibleForTest()); | |
114 } | |
115 | |
116 // Verifies the stop cast button invokes the JavaScript function | |
117 // "stopMirroring('user-stop')". | |
118 IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, | |
119 CastTrayStopButtonStopsCast) { | |
120 // Add a receiver that is casting. | |
121 auto extension = LoadCastTestExtension(); | |
achuithb
2015/07/08 22:04:55
Type is not clear
jdufault
2015/07/09 23:12:56
Done.
| |
122 ExecuteJavaScript(extension, "addReceiver('id', 'name', 'title', 1)"); | |
123 | |
124 // Stop the cast using the UI. | |
125 ash::TrayCast* tray = GetTrayCast(); | |
126 tray->StopCastForTest(); | |
127 ExecutePendingJavaScript(extension); | |
128 | |
129 // Verify that stopMirroring was called. | |
130 scoped_ptr<base::Value> wasStopMirroringCalled = | |
131 ExecuteJavaScript(extension, "wasStopMirroringCalledWithUserStop()"); | |
132 bool result; | |
133 if (wasStopMirroringCalled->GetAsBoolean(&result) == false) { | |
134 FAIL(); // Unknown return type for wasStopMirroringCalled(). | |
achuithb
2015/07/08 22:04:55
Why not
EXPECT_TRUE(wasStopMirroringCalled->GetAsB
jdufault
2015/07/09 23:12:58
Done.
| |
135 } | |
136 EXPECT_TRUE(result); | |
137 } | |
138 | |
139 // Verifies that the start cast button invokes "launchDesktopMirroring(...)". | |
140 IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, | |
141 CastTrayStartButtonStartsCast) { | |
142 // Add a receiver. | |
143 auto extension = LoadCastTestExtension(); | |
144 ExecuteJavaScript(extension, "addReceiver('id', 'name', 'title', 1)"); | |
145 | |
146 // Begin casting something with the id "id" | |
147 ash::TrayCast* tray = GetTrayCast(); | |
148 | |
149 // Upcast because CreateDetailedView is not visible in TrayCast | |
150 ((ash::SystemTrayItem*)tray) | |
achuithb
2015/07/08 22:04:55
Please use static_cast here
jdufault
2015/07/09 23:12:57
Done.
| |
151 ->CreateDetailedView(ash::user::LoginStatus::LOGGED_IN_USER); | |
152 ExecutePendingJavaScript(extension); | |
153 tray->StartCastForTest("id"); | |
achuithb
2015/07/08 22:04:55
test_id
jdufault
2015/07/09 23:12:57
Done.
| |
154 ExecutePendingJavaScript(extension); | |
155 | |
156 // Verify that launchDesktopMirroring was called with "id" | |
157 scoped_ptr<base::Value> launchDesktopMirroringReceiverId = | |
158 ExecuteJavaScript(extension, "getLaunchDesktopMirroringReceiverId()"); | |
159 std::string result; | |
160 if (launchDesktopMirroringReceiverId->GetAsString(&result) == false) { | |
achuithb
2015/07/08 22:04:55
EXPECT_TRUE
jdufault
2015/07/09 23:12:57
Done.
| |
161 FAIL(); // Unknown return type for launchDesktopMirroringReceiverId. | |
162 } | |
163 EXPECT_EQ("id", result); | |
164 } | |
165 | |
166 IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, CastTrayOpenOptions) { | |
167 LoadCastTestExtension(); | |
168 | |
169 auto cast_config_delegate = ash::Shell::GetInstance() | |
achuithb
2015/07/08 22:04:54
Type is not clear
jdufault
2015/07/09 23:12:57
Done.
| |
170 ->system_tray_delegate() | |
171 ->GetCastConfigDelegate(); | |
172 cast_config_delegate->LaunchCastOptions(); | |
173 | |
174 auto url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL(); | |
achuithb
2015/07/08 22:04:55
GURL
jdufault
2015/07/09 23:12:57
Done.
| |
175 EXPECT_TRUE(base::StringPiece(url.GetContent()).ends_with("options.html")); | |
achuithb
2015/07/08 22:04:55
Hmm, this seems a bit fragile since the cast exten
jdufault
2015/07/09 23:12:57
I'm not sure it's even a good test, because the mo
achuithb
2015/07/10 21:32:06
So the mock extension is not launching the real op
jdufault
2015/07/13 21:19:57
It's not the extension which is launching the opti
| |
176 } | |
177 | |
178 } // namespace chromeos | |
OLD | NEW |