OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h" |
12 #include "chrome/browser/extensions/extension_apitest.h" | 13 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/tab_helper.h" | 14 #include "chrome/browser/extensions/tab_helper.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
17 #include "chrome/browser/ui/tabs/tab_utils.h" | 18 #include "chrome/browser/ui/tabs/tab_utils.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
20 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 #else | 83 #else |
83 // TODO(miu): Look into enabling these tests for the Debug build bots once | 84 // TODO(miu): Look into enabling these tests for the Debug build bots once |
84 // they prove to be stable again on the Release bots. | 85 // they prove to be stable again on the Release bots. |
85 // http://crbug.com/396413 | 86 // http://crbug.com/396413 |
86 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 87 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
87 "run-tab-capture-api-pixel-tests"); | 88 "run-tab-capture-api-pixel-tests"); |
88 #endif | 89 #endif |
89 } | 90 } |
90 }; | 91 }; |
91 | 92 |
| 93 // Tests the logic that examines the constraints to determine the starting |
| 94 // off-screen tab size. |
| 95 TEST(TabCaptureCaptureOffscreenTabTest, DetermineInitialSize) { |
| 96 using extensions::api::tab_capture::CaptureOptions; |
| 97 using extensions::api::tab_capture::MediaStreamConstraint; |
| 98 |
| 99 // Empty options --> 1280x720 |
| 100 CaptureOptions options; |
| 101 EXPECT_EQ(gfx::Size(1280, 720), |
| 102 TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
| 103 options)); |
| 104 |
| 105 // Use specified mandatory maximum size. |
| 106 options.video_constraints.reset(new MediaStreamConstraint()); |
| 107 base::DictionaryValue* properties = |
| 108 &options.video_constraints->mandatory.additional_properties; |
| 109 properties->SetInteger("maxWidth", 123); |
| 110 properties->SetInteger("maxHeight", 456); |
| 111 EXPECT_EQ(gfx::Size(123, 456), |
| 112 TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
| 113 options)); |
| 114 |
| 115 // Use default size if larger than mandatory minimum size. Else, use |
| 116 // mandatory minimum size. |
| 117 options.video_constraints.reset(new MediaStreamConstraint()); |
| 118 properties = &options.video_constraints->mandatory.additional_properties; |
| 119 properties->SetInteger("minWidth", 123); |
| 120 properties->SetInteger("minHeight", 456); |
| 121 EXPECT_EQ(gfx::Size(1280, 720), |
| 122 TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
| 123 options)); |
| 124 properties->SetInteger("minWidth", 2560); |
| 125 properties->SetInteger("minHeight", 1440); |
| 126 EXPECT_EQ(gfx::Size(2560, 1440), |
| 127 TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
| 128 options)); |
| 129 |
| 130 // Use specified optional maximum size, if no mandatory size was specified. |
| 131 options.video_constraints.reset(new MediaStreamConstraint()); |
| 132 options.video_constraints->optional.reset( |
| 133 new MediaStreamConstraint::Optional()); |
| 134 properties = &options.video_constraints->optional->additional_properties; |
| 135 properties->SetInteger("maxWidth", 456); |
| 136 properties->SetInteger("maxHeight", 123); |
| 137 EXPECT_EQ(gfx::Size(456, 123), |
| 138 TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
| 139 options)); |
| 140 // ...unless a mandatory minimum size was specified: |
| 141 options.video_constraints->mandatory.additional_properties.SetInteger( |
| 142 "minWidth", 500); |
| 143 options.video_constraints->mandatory.additional_properties.SetInteger( |
| 144 "minHeight", 600); |
| 145 EXPECT_EQ(gfx::Size(500, 600), |
| 146 TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
| 147 options)); |
| 148 |
| 149 // Use default size if larger than optional minimum size. Else, use optional |
| 150 // minimum size. |
| 151 options.video_constraints.reset(new MediaStreamConstraint()); |
| 152 options.video_constraints->optional.reset( |
| 153 new MediaStreamConstraint::Optional()); |
| 154 properties = &options.video_constraints->optional->additional_properties; |
| 155 properties->SetInteger("minWidth", 9999); |
| 156 properties->SetInteger("minHeight", 8888); |
| 157 EXPECT_EQ(gfx::Size(9999, 8888), |
| 158 TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
| 159 options)); |
| 160 } |
| 161 |
92 // Tests API behaviors, including info queries, and constraints violations. | 162 // Tests API behaviors, including info queries, and constraints violations. |
93 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, ApiTests) { | 163 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, ApiTests) { |
94 AddExtensionToCommandLineWhitelist(); | 164 AddExtensionToCommandLineWhitelist(); |
95 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "api_tests.html")) << message_; | 165 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "api_tests.html")) << message_; |
96 } | 166 } |
97 | 167 |
| 168 // Tests that there is a maximum limitation to the number of simultaneous |
| 169 // off-screen tabs. |
| 170 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MaxOffscreenTabs) { |
| 171 AddExtensionToCommandLineWhitelist(); |
| 172 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "max_offscreen_tabs.html")) |
| 173 << message_; |
| 174 } |
| 175 |
98 // Tests that tab capture video frames can be received in a VIDEO element. | 176 // Tests that tab capture video frames can be received in a VIDEO element. |
99 IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, EndToEndWithoutRemoting) { | 177 IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, EndToEndWithoutRemoting) { |
100 if (IsTooIntensiveForThisPlatform()) { | 178 if (IsTooIntensiveForThisPlatform()) { |
101 LOG(WARNING) << "Skipping this CPU-intensive test on this platform/build."; | 179 LOG(WARNING) << "Skipping this CPU-intensive test on this platform/build."; |
102 return; | 180 return; |
103 } | 181 } |
104 AddExtensionToCommandLineWhitelist(); | 182 AddExtensionToCommandLineWhitelist(); |
105 ASSERT_TRUE(RunExtensionSubtest( | 183 ASSERT_TRUE(RunExtensionSubtest( |
106 "tab_capture", "end_to_end.html?method=local&colorDeviation=10")) | 184 "tab_capture", "end_to_end.html?method=local&colorDeviation=10")) |
107 << message_; | 185 << message_; |
108 } | 186 } |
109 | 187 |
110 // Tests that video frames are captured, transported via WebRTC, and finally | 188 // Tests that video frames are captured, transported via WebRTC, and finally |
111 // received in a VIDEO element. More allowance is provided for color deviation | 189 // received in a VIDEO element. More allowance is provided for color deviation |
112 // because of the additional layers of video processing performed within | 190 // because of the additional layers of video processing performed within |
113 // WebRTC. | 191 // WebRTC. |
114 IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, EndToEndThroughWebRTC) { | 192 IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, EndToEndThroughWebRTC) { |
115 if (IsTooIntensiveForThisPlatform()) { | 193 if (IsTooIntensiveForThisPlatform()) { |
116 LOG(WARNING) << "Skipping this CPU-intensive test on this platform/build."; | 194 LOG(WARNING) << "Skipping this CPU-intensive test on this platform/build."; |
117 return; | 195 return; |
118 } | 196 } |
119 AddExtensionToCommandLineWhitelist(); | 197 AddExtensionToCommandLineWhitelist(); |
120 ASSERT_TRUE(RunExtensionSubtest( | 198 ASSERT_TRUE(RunExtensionSubtest( |
121 "tab_capture", "end_to_end.html?method=webrtc&colorDeviation=50")) | 199 "tab_capture", "end_to_end.html?method=webrtc&colorDeviation=50")) |
122 << message_; | 200 << message_; |
123 } | 201 } |
124 | 202 |
| 203 // Tests that tab capture video frames can be received in a VIDEO element from |
| 204 // an off-screen tab. |
| 205 IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, OffscreenTabEndToEnd) { |
| 206 if (IsTooIntensiveForThisPlatform()) { |
| 207 LOG(WARNING) << "Skipping this CPU-intensive test on this platform/build."; |
| 208 return; |
| 209 } |
| 210 AddExtensionToCommandLineWhitelist(); |
| 211 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "offscreen_end_to_end.html")) |
| 212 << message_; |
| 213 } |
| 214 |
| 215 // Tests that off-screen tabs can't do evil things (e.g., access local files). |
| 216 IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, OffscreenTabEvilTests) { |
| 217 if (IsTooIntensiveForThisPlatform()) { |
| 218 LOG(WARNING) << "Skipping this CPU-intensive test on this platform/build."; |
| 219 return; |
| 220 } |
| 221 AddExtensionToCommandLineWhitelist(); |
| 222 ASSERT_TRUE(RunExtensionSubtest("tab_capture", "offscreen_evil_tests.html")) |
| 223 << message_; |
| 224 } |
| 225 |
125 // http://crbug.com/177163 | 226 // http://crbug.com/177163 |
126 #if defined(OS_WIN) && !defined(NDEBUG) | 227 #if defined(OS_WIN) && !defined(NDEBUG) |
127 #define MAYBE_GetUserMediaTest DISABLED_GetUserMediaTest | 228 #define MAYBE_GetUserMediaTest DISABLED_GetUserMediaTest |
128 #else | 229 #else |
129 #define MAYBE_GetUserMediaTest GetUserMediaTest | 230 #define MAYBE_GetUserMediaTest GetUserMediaTest |
130 #endif | 231 #endif |
131 // Tests that getUserMedia() is NOT a way to start tab capture. | 232 // Tests that getUserMedia() is NOT a way to start tab capture. |
132 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GetUserMediaTest) { | 233 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GetUserMediaTest) { |
133 ExtensionTestMessageListener listener("ready", true); | 234 ExtensionTestMessageListener listener("ready", true); |
134 | 235 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 return; | 457 return; |
357 } | 458 } |
358 content::RunMessageLoop(); | 459 content::RunMessageLoop(); |
359 } | 460 } |
360 browser()->tab_strip_model()->RemoveObserver(&observer); | 461 browser()->tab_strip_model()->RemoveObserver(&observer); |
361 } | 462 } |
362 | 463 |
363 } // namespace | 464 } // namespace |
364 | 465 |
365 } // namespace extensions | 466 } // namespace extensions |
OLD | NEW |