Bug 1644653 [wpt PR 24078] - wpt: screen enumeration: test to verify screen id, a=testonly
authorArnaud Mandy <arnaud.mandy@intel.com>
Mon, 22 Jun 2020 10:43:32 +0000
changeset 536837 f50ab929ee2e42f0bacb211d02471c60d03344b8
parent 536836 7446debba5ecc55de7e2110e1952fee0a6dfbbce
child 536838 ecd53890ab847f0437d9392a6247a17a938c328c
push id37533
push userdluca@mozilla.com
push dateTue, 23 Jun 2020 21:38:40 +0000
treeherdermozilla-central@d48aa0f0aa0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1644653, 24078, 1075656, 2238112, 779689
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1644653 [wpt PR 24078] - wpt: screen enumeration: test to verify screen id, a=testonly Automatic update from web-platform-tests wpt: screen enumeration: test to verify screen id Test to verify screen id. adding 3 displays to display vector. getScreens() should return 3 screens with ids 0,1,2. removing middle display from display vector. getScreens() should return 2 screens with ids 0,1. removing last display from display vector. getScreens() should return 1 screen with id 0. Bug: 1075656 Change-Id: Ib671b760353766d21330b95833b983c9b5e4737f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238112 Reviewed-by: Michael Wasserman <msw@chromium.org> Commit-Queue: Arnaud Mandy <arnaud.mandy@intel.com> Cr-Commit-Position: refs/heads/master@{#779689} -- wpt-commits: df2272857e29491bdb6c8ab77a8adec2f11757d2 wpt-pr: 24078
testing/web-platform/tests/resources/chromium/mock-screenenumeration.js
testing/web-platform/tests/screen_enumeration/README.md
testing/web-platform/tests/screen_enumeration/getScreens.values.https.html
--- a/testing/web-platform/tests/resources/chromium/mock-screenenumeration.js
+++ b/testing/web-platform/tests/resources/chromium/mock-screenenumeration.js
@@ -28,16 +28,23 @@ var ScreenEnumerationTest = (() => {
     setSuccess(success) {
       this.success_ = success;
     }
 
     addDisplay(display) {
       this.displays_.push(display);
     }
 
+    removeDisplay(id) {
+      for (var i = 0; i < this.displays_.length; i++) {
+        if (this.displays_[i].id === id)
+          this.displays_.splice(i,1);
+      }
+    }
+
     async getDisplays() {
       return Promise.resolve({
         displays: this.displays_,
         internalId: this.internalId_,
         primaryId: this.primaryId_,
         success: this.success_,
       });
     }
--- a/testing/web-platform/tests/screen_enumeration/README.md
+++ b/testing/web-platform/tests/screen_enumeration/README.md
@@ -11,16 +11,17 @@ The `ScreenEnumerationTest` interface is
     getMockScreenEnumeration(); // Returns `MockScreenEnumeration` interface.
   };
 
   class MockScreenEnumeration {
     reset(); Empties data of created mock displays.
     setId(internalId, primaryId); // Set primary screen and internal screen IDs.
     setSuccess(success); // Set boolean to validate getDisplays() returned values.
     addDisplay(display); // Push display to the display vector.
+    removeDisplay(id); // Remove display from the display vector.
     async getDisplays(); // Interceptor of getDisplays (screen_enumeration.mojom).
   };
 ```
 
 Other helper-functions are located in screenenumeration-helpers.js
 ```
 makeDisplay(id, bounds, work_area, scale_factor); // Create display object.
 ```
--- a/testing/web-platform/tests/screen_enumeration/getScreens.values.https.html
+++ b/testing/web-platform/tests/screen_enumeration/getScreens.values.https.html
@@ -18,17 +18,17 @@ screen_enumeration_test(async (t, mockSc
 
   mockScreenEnum.addDisplay(display1);
   mockScreenEnum.setIds(mockScreenEnum.displays_[0].id, mockScreenEnum.displays_[0].id);
   mockScreenEnum.setSuccess(true);
 
   // Grant window-placement permissions for testdriver.
   await test_driver.set_permission({name: "window-placement"}, "granted");
 
-  // This call is calling GetDisplays, which should fall in interceptor.
+  // This returns the mocked displays via MockScreenEnumeration implementation.
   const screens = await self.getScreens();
 
   assert_equals(screens.length, 1);
 
   assert_equals(screens[0].left, 0);
   assert_equals(screens[0].top, 10);
   assert_equals(screens[0].width, 1200);
   assert_equals(screens[0].height, 800);
@@ -36,9 +36,57 @@ screen_enumeration_test(async (t, mockSc
   assert_equals(screens[0].availTop, 30);
   assert_equals(screens[0].availWidth, 1000);
   assert_equals(screens[0].availHeight, 600);
   assert_equals(screens[0].primary, true);
   assert_equals(screens[0].internal, true);
   assert_equals(screens[0].scaleFactor, 1.0);
   assert_equals(screens[0].id, "0");
 }, "getScreens() returns a single mocked screen");
+
+screen_enumeration_test(async (t, mockScreenEnum) => {
+  let display1 = makeDisplay(10,
+                             {x: 0, y: 10, width: 1200, height: 800},
+                             {x: 20, y: 30, width: 1000, height: 600},
+                             1.0);
+
+  let display2 = makeDisplay(11,
+                             {x: 0, y: 10, width: 1200, height: 800},
+                             {x: 20, y: 30, width: 1000, height: 600},
+                             1.0);
+
+  let display3 = makeDisplay(12,
+                             {x: 0, y: 10, width: 1200, height: 800},
+                             {x: 20, y: 30, width: 1000, height: 600},
+                             1.0);
+
+  mockScreenEnum.addDisplay(display1);
+  mockScreenEnum.addDisplay(display2);
+  mockScreenEnum.addDisplay(display3);
+  mockScreenEnum.setIds(mockScreenEnum.displays_[0].id, mockScreenEnum.displays_[0].id);
+  mockScreenEnum.setSuccess(true);
+
+  // Grant window-placement permissions for testdriver.
+  await test_driver.set_permission({name: "window-placement"}, "granted");
+
+  // This returns the mocked displays via MockScreenEnumeration implementation.
+  let screens = await self.getScreens();
+
+  assert_equals(screens.length, 3);
+  assert_equals(screens[0].id, "0");
+  assert_equals(screens[1].id, "1");
+  assert_equals(screens[2].id, "2");
+
+  mockScreenEnum.removeDisplay(display2.id);
+
+  screens = await self.getScreens();
+  assert_equals(screens.length, 2);
+  assert_equals(screens[0].id, "0");
+  assert_equals(screens[1].id, "1");
+
+  mockScreenEnum.removeDisplay(display1.id);
+
+  screens = await self.getScreens();
+  assert_equals(screens.length, 1);
+  assert_equals(screens[0].id, "0");
+}, "getScreens() supports multiple mocked screens");
+
 </script>