OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "ash/shell.h" | 5 #include "ash/shell.h" |
6 #include "ash/system/cast/tray_cast.h" | 6 #include "ash/system/cast/tray_cast.h" |
7 #include "ash/system/tray/system_tray.h" | 7 #include "ash/system/tray/system_tray.h" |
8 #include "ash/system/tray/system_tray_delegate.h" | 8 #include "ash/system/tray/system_tray_delegate.h" |
9 #include "ash/system/tray/system_tray_item.h" | 9 #include "ash/system/tray/system_tray_item.h" |
10 #include "ash/test/tray_cast_test_api.h" | 10 #include "ash/test/tray_cast_test_api.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
12 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
17 #include "extensions/browser/process_manager.h" | 18 #include "extensions/browser/process_manager.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Execute JavaScript within the context of the extension. Returns the result | 22 // Execute JavaScript within the context of the extension. Returns the result |
22 // of the execution. | 23 // of the execution. |
23 scoped_ptr<base::Value> ExecuteJavaScript( | 24 std::unique_ptr<base::Value> ExecuteJavaScript( |
24 const extensions::Extension* extension, | 25 const extensions::Extension* extension, |
25 const std::string& javascript) { | 26 const std::string& javascript) { |
26 extensions::ProcessManager* pm = | 27 extensions::ProcessManager* pm = |
27 extensions::ProcessManager::Get(ProfileManager::GetActiveUserProfile()); | 28 extensions::ProcessManager::Get(ProfileManager::GetActiveUserProfile()); |
28 content::RenderViewHost* host = | 29 content::RenderViewHost* host = |
29 pm->GetBackgroundHostForExtension(extension->id())->render_view_host(); | 30 pm->GetBackgroundHostForExtension(extension->id())->render_view_host(); |
30 return content::ExecuteScriptAndGetValue(host->GetMainFrame(), javascript); | 31 return content::ExecuteScriptAndGetValue(host->GetMainFrame(), javascript); |
31 } | 32 } |
32 | 33 |
33 // Returns the current value within a global JavaScript variable. | 34 // Returns the current value within a global JavaScript variable. |
34 scoped_ptr<base::Value> GetJavaScriptVariable( | 35 std::unique_ptr<base::Value> GetJavaScriptVariable( |
35 const extensions::Extension* extension, | 36 const extensions::Extension* extension, |
36 const std::string& variable) { | 37 const std::string& variable) { |
37 return ExecuteJavaScript(extension, | 38 return ExecuteJavaScript(extension, |
38 "(function() { return " + variable + "; })()"); | 39 "(function() { return " + variable + "; })()"); |
39 } | 40 } |
40 | 41 |
41 bool GetJavaScriptStringVariable(const extensions::Extension* extension, | 42 bool GetJavaScriptStringVariable(const extensions::Extension* extension, |
42 const std::string& variable, | 43 const std::string& variable, |
43 std::string* result) { | 44 std::string* result) { |
44 scoped_ptr<base::Value> value = GetJavaScriptVariable(extension, variable); | 45 std::unique_ptr<base::Value> value = |
| 46 GetJavaScriptVariable(extension, variable); |
45 return value->GetAsString(result); | 47 return value->GetAsString(result); |
46 } | 48 } |
47 | 49 |
48 bool GetJavaScriptBooleanVariable(const extensions::Extension* extension, | 50 bool GetJavaScriptBooleanVariable(const extensions::Extension* extension, |
49 const std::string& variable, | 51 const std::string& variable, |
50 bool* result) { | 52 bool* result) { |
51 scoped_ptr<base::Value> value = GetJavaScriptVariable(extension, variable); | 53 std::unique_ptr<base::Value> value = |
| 54 GetJavaScriptVariable(extension, variable); |
52 return value->GetAsBoolean(result); | 55 return value->GetAsBoolean(result); |
53 } | 56 } |
54 | 57 |
55 // Ensures that all pending JavaScript execution callbacks are invoked. | 58 // Ensures that all pending JavaScript execution callbacks are invoked. |
56 void ExecutePendingJavaScript(const extensions::Extension* extension) { | 59 void ExecutePendingJavaScript(const extensions::Extension* extension) { |
57 ExecuteJavaScript(extension, std::string()); | 60 ExecuteJavaScript(extension, std::string()); |
58 } | 61 } |
59 | 62 |
60 // Invokes tray->StartCast(id) and returns true if launchDesktopMirroring was | 63 // Invokes tray->StartCast(id) and returns true if launchDesktopMirroring was |
61 // called with the same id. This automatically creates/destroys the detail view | 64 // called with the same id. This automatically creates/destroys the detail view |
62 // and notifies the tray that Chrome has begun casting. | 65 // and notifies the tray that Chrome has begun casting. |
63 bool StartCastWithVerification(const extensions::Extension* extension, | 66 bool StartCastWithVerification(const extensions::Extension* extension, |
64 ash::TrayCast* tray, | 67 ash::TrayCast* tray, |
65 const std::string& receiver_id) { | 68 const std::string& receiver_id) { |
66 ash::SystemTrayItem* system_tray_item = tray; | 69 ash::SystemTrayItem* system_tray_item = tray; |
67 ash::TrayCastTestAPI test_tray(tray); | 70 ash::TrayCastTestAPI test_tray(tray); |
68 | 71 |
69 // We will simulate a button click in the detail view to begin the cast, so we | 72 // We will simulate a button click in the detail view to begin the cast, so we |
70 // need to make a detail view available. | 73 // need to make a detail view available. |
71 scoped_ptr<views::View> detailed_view = | 74 std::unique_ptr<views::View> detailed_view = |
72 make_scoped_ptr(system_tray_item->CreateDetailedView( | 75 base::WrapUnique(system_tray_item->CreateDetailedView( |
73 ash::user::LoginStatus::LOGGED_IN_USER)); | 76 ash::user::LoginStatus::LOGGED_IN_USER)); |
74 | 77 |
75 // Clear out any old state and execute any pending JS calls created from the | 78 // Clear out any old state and execute any pending JS calls created from the |
76 // CreateDetailedView call. | 79 // CreateDetailedView call. |
77 ExecuteJavaScript(extension, "launchDesktopMirroringReceiverId = ''"); | 80 ExecuteJavaScript(extension, "launchDesktopMirroringReceiverId = ''"); |
78 | 81 |
79 // Tell the tray item that Chrome has started casting. | 82 // Tell the tray item that Chrome has started casting. |
80 test_tray.StartCast(receiver_id); | 83 test_tray.StartCast(receiver_id); |
81 test_tray.OnCastingSessionStartedOrStopped(true); | 84 test_tray.OnCastingSessionStartedOrStopped(true); |
82 | 85 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 cast_config_delegate->LaunchCastOptions(); | 279 cast_config_delegate->LaunchCastOptions(); |
277 | 280 |
278 const GURL url = | 281 const GURL url = |
279 browser()->tab_strip_model()->GetActiveWebContents()->GetURL(); | 282 browser()->tab_strip_model()->GetActiveWebContents()->GetURL(); |
280 EXPECT_TRUE(base::StringPiece(url.GetContent()).ends_with("options.html")); | 283 EXPECT_TRUE(base::StringPiece(url.GetContent()).ends_with("options.html")); |
281 | 284 |
282 UninstallExtension(extension->id()); | 285 UninstallExtension(extension->id()); |
283 } | 286 } |
284 | 287 |
285 } // namespace chromeos | 288 } // namespace chromeos |
OLD | NEW |