Index: chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc |
diff --git a/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc b/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc |
index e618eeac7bb44747c141ec2fdb54845be6d2b94f..786554dc34d29887c43992b93ea4bb2c5e7df303 100644 |
--- a/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc |
+++ b/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc |
@@ -9,6 +9,7 @@ |
#include "base/strings/stringprintf.h" |
#include "base/thread_task_runner_handle.h" |
#include "base/time/time.h" |
+#include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h" |
#include "chrome/browser/extensions/extension_apitest.h" |
#include "chrome/browser/extensions/tab_helper.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -89,12 +90,89 @@ class TabCaptureApiPixelTest : public TabCaptureApiTest { |
} |
}; |
+// Tests the logic that examines the constraints to determine the starting |
+// off-screen tab size. |
+TEST(TabCaptureCaptureOffscreenTabTest, DetermineInitialSize) { |
+ using extensions::api::tab_capture::CaptureOptions; |
+ using extensions::api::tab_capture::MediaStreamConstraint; |
+ |
+ // Empty options --> 1280x720 |
+ CaptureOptions options; |
+ EXPECT_EQ(gfx::Size(1280, 720), |
+ TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
+ options)); |
+ |
+ // Use specified mandatory maximum size. |
+ options.video_constraints.reset(new MediaStreamConstraint()); |
+ base::DictionaryValue* properties = |
+ &options.video_constraints->mandatory.additional_properties; |
+ properties->SetInteger("maxWidth", 123); |
+ properties->SetInteger("maxHeight", 456); |
+ EXPECT_EQ(gfx::Size(123, 456), |
+ TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
+ options)); |
+ |
+ // Use default size if larger than mandatory minimum size. Else, use |
+ // mandatory minimum size. |
+ options.video_constraints.reset(new MediaStreamConstraint()); |
+ properties = &options.video_constraints->mandatory.additional_properties; |
+ properties->SetInteger("minWidth", 123); |
+ properties->SetInteger("minHeight", 456); |
+ EXPECT_EQ(gfx::Size(1280, 720), |
+ TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
+ options)); |
+ properties->SetInteger("minWidth", 2560); |
+ properties->SetInteger("minHeight", 1440); |
+ EXPECT_EQ(gfx::Size(2560, 1440), |
+ TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
+ options)); |
+ |
+ // Use specified optional maximum size, if no mandatory size was specified. |
+ options.video_constraints.reset(new MediaStreamConstraint()); |
+ options.video_constraints->optional.reset( |
+ new MediaStreamConstraint::Optional()); |
+ properties = &options.video_constraints->optional->additional_properties; |
+ properties->SetInteger("maxWidth", 456); |
+ properties->SetInteger("maxHeight", 123); |
+ EXPECT_EQ(gfx::Size(456, 123), |
+ TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
+ options)); |
+ // ...unless a mandatory minimum size was specified: |
+ options.video_constraints->mandatory.additional_properties.SetInteger( |
+ "minWidth", 500); |
+ options.video_constraints->mandatory.additional_properties.SetInteger( |
+ "minHeight", 600); |
+ EXPECT_EQ(gfx::Size(500, 600), |
+ TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
+ options)); |
+ |
+ // Use default size if larger than optional minimum size. Else, use optional |
+ // minimum size. |
+ options.video_constraints.reset(new MediaStreamConstraint()); |
+ options.video_constraints->optional.reset( |
+ new MediaStreamConstraint::Optional()); |
+ properties = &options.video_constraints->optional->additional_properties; |
+ properties->SetInteger("minWidth", 9999); |
+ properties->SetInteger("minHeight", 8888); |
+ EXPECT_EQ(gfx::Size(9999, 8888), |
+ TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
+ options)); |
+} |
+ |
// Tests API behaviors, including info queries, and constraints violations. |
IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, ApiTests) { |
AddExtensionToCommandLineWhitelist(); |
ASSERT_TRUE(RunExtensionSubtest("tab_capture", "api_tests.html")) << message_; |
} |
+// Tests that there is a maximum limitation to the number of simultaneous |
+// off-screen tabs. |
+IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MaxOffscreenTabs) { |
+ AddExtensionToCommandLineWhitelist(); |
+ ASSERT_TRUE(RunExtensionSubtest("tab_capture", "max_offscreen_tabs.html")) |
+ << message_; |
+} |
+ |
// Tests that tab capture video frames can be received in a VIDEO element. |
IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, EndToEndWithoutRemoting) { |
if (IsTooIntensiveForThisPlatform()) { |
@@ -122,6 +200,29 @@ IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, EndToEndThroughWebRTC) { |
<< message_; |
} |
+// Tests that tab capture video frames can be received in a VIDEO element from |
+// an off-screen tab. |
+IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, OffscreenTabEndToEnd) { |
+ if (IsTooIntensiveForThisPlatform()) { |
+ LOG(WARNING) << "Skipping this CPU-intensive test on this platform/build."; |
+ return; |
+ } |
+ AddExtensionToCommandLineWhitelist(); |
+ ASSERT_TRUE(RunExtensionSubtest("tab_capture", "offscreen_end_to_end.html")) |
+ << message_; |
+} |
+ |
+// Tests that off-screen tabs can't do evil things (e.g., access local files). |
+IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, OffscreenTabEvilTests) { |
+ if (IsTooIntensiveForThisPlatform()) { |
+ LOG(WARNING) << "Skipping this CPU-intensive test on this platform/build."; |
+ return; |
+ } |
+ AddExtensionToCommandLineWhitelist(); |
+ ASSERT_TRUE(RunExtensionSubtest("tab_capture", "offscreen_evil_tests.html")) |
+ << message_; |
+} |
+ |
// http://crbug.com/177163 |
#if defined(OS_WIN) && !defined(NDEBUG) |
#define MAYBE_GetUserMediaTest DISABLED_GetUserMediaTest |