Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: chrome/test/data/webui/settings/fake_system_display.js

Issue 2084673003: MD Settings: Add display layout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_547080_display_settings6
Patch Set: Nit Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/webui/settings/device_page_tests.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /** 5 /**
6 * @fileoverview Fake implementation of chrome.system.display for testing. 6 * @fileoverview Fake implementation of chrome.system.display for testing.
7 */ 7 */
8 cr.define('settings', function() { 8 cr.define('settings', function() {
9 /** 9 /**
10 * Fake of the chrome.settings.display API. 10 * Fake of the chrome.settings.display API.
11 * @constructor 11 * @constructor
12 * @implements {SystemDisplay} 12 * @implements {SystemDisplay}
13 */ 13 */
14 function FakeSystemDisplay() { 14 function FakeSystemDisplay() {
15 /** @type {!Array<!chrome.system.display.DisplayUnitInfo>} */ 15 /** @type {!Array<!chrome.system.display.DisplayUnitInfo>} */
16 this.fakeDisplays = []; 16 this.fakeDisplays = [];
17 this.fakeLayouts = [];
17 this.getInfoCalled = new PromiseResolver(); 18 this.getInfoCalled = new PromiseResolver();
19 this.getLayoutCalled = new PromiseResolver();
18 } 20 }
19 21
20 FakeSystemDisplay.prototype = { 22 FakeSystemDisplay.prototype = {
21 // Public testing methods. 23 // Public testing methods.
22 /** 24 /**
23 * @param {!chrome.system.display.DisplayUnitInfo>} display 25 * @param {!chrome.system.display.DisplayUnitInfo>} display
24 */ 26 */
25 addDisplayForTest: function(display) { this.fakeDisplays.push(display); }, 27 addDisplayForTest: function(display) {
28 this.fakeDisplays.push(display);
29 this.updateLayouts_();
30 },
26 31
27 // SystemDisplay overrides. 32 // SystemDisplay overrides.
28 /** @override */ 33 /** @override */
29 getInfo: function(callback) { 34 getInfo: function(callback) {
30 setTimeout(function() { 35 setTimeout(function() {
31 // Create a shallow copy to trigger Polymer data binding updates. 36 // Create a shallow copy to trigger Polymer data binding updates.
32 var displays; 37 var displays;
33 if (this.fakeDisplays.length > 0 && 38 if (this.fakeDisplays.length > 0 &&
34 this.fakeDisplays[0].mirroringSourceId) { 39 this.fakeDisplays[0].mirroringSourceId) {
35 // When mirroring is enabled, send only the info for the display 40 // When mirroring is enabled, send only the info for the display
(...skipping 14 matching lines...) Expand all
50 55
51 /** @override */ 56 /** @override */
52 setDisplayProperties: function(id, info, callback) { 57 setDisplayProperties: function(id, info, callback) {
53 var display = this.getFakeDisplay_(id); 58 var display = this.getFakeDisplay_(id);
54 if (!display) { 59 if (!display) {
55 chrome.runtime.lastError = 'Display not found.'; 60 chrome.runtime.lastError = 'Display not found.';
56 callback(); 61 callback();
57 } 62 }
58 63
59 if (info.mirroringSourceId != undefined) { 64 if (info.mirroringSourceId != undefined) {
60 for (var d of this.fakeDisplays) 65 for (let d of this.fakeDisplays)
61 d.mirroringSourceId = info.mirroringSourceId; 66 d.mirroringSourceId = info.mirroringSourceId;
62 } 67 }
63 68
64 if (info.isPrimary != undefined) { 69 if (info.isPrimary != undefined) {
65 var havePrimary = info.isPrimary; 70 var havePrimary = info.isPrimary;
66 for (var d of this.fakeDisplays) { 71 for (let d of this.fakeDisplays) {
67 if (d.id == id) { 72 if (d.id == id) {
68 d.isPrimary = info.isPrimary; 73 d.isPrimary = info.isPrimary;
69 } else if (havePrimary) { 74 } else if (havePrimary) {
70 d.isPrimary = false; 75 d.isPrimary = false;
71 } else { 76 } else {
72 d.isPrimary = true; 77 d.isPrimary = true;
73 havePrimary = true; 78 havePrimary = true;
74 } 79 }
75 } 80 }
81 this.updateLayouts_();
76 } 82 }
77 if (info.rotation != undefined) 83 if (info.rotation != undefined)
78 display.rotation = info.rotation; 84 display.rotation = info.rotation;
79 }, 85 },
80 86
81 /** @override */ 87 /** @override */
88 getDisplayLayout(callback) {
89 setTimeout(function() {
90 // Create a shallow copy to trigger Polymer data binding updates.
91 callback(this.fakeLayouts.slice());
92 this.getLayoutCalled.resolve();
93 // Reset the promise resolver.
94 this.getLayoutCalled = new PromiseResolver();
95 }.bind(this));
96 },
97
98 /** @override */
99 setDisplayLayout(layouts, callback) {
100 this.fakeLayouts = layouts;
101 callback();
102 },
103
104 /** @override */
82 onDisplayChanged: new FakeChromeEvent(), 105 onDisplayChanged: new FakeChromeEvent(),
83 106
84 /** @private */ 107 /** @private */
85 getFakeDisplay_(id) { 108 getFakeDisplay_(id) {
86 var idx = this.fakeDisplays.findIndex(function(display) { 109 var idx = this.fakeDisplays.findIndex(function(display) {
87 return display.id == id; 110 return display.id == id;
88 }); 111 });
89 if (idx >= 0) 112 if (idx >= 0)
90 return this.fakeDisplays[idx]; 113 return this.fakeDisplays[idx];
91 return undefined; 114 return undefined;
115 },
116
117 /** @private */
118 updateLayouts_() {
119 this.fakeLayouts = [];
120 var primaryId = '';
121 for (let d of this.fakeDisplays) {
122 if (d.isPrimary) {
123 primaryId = d.id;
124 break;
125 }
126 }
127 for (let d of this.fakeDisplays) {
128 this.fakeLayouts.push({
129 id: d.id,
130 parentId: d.isPrimary ? '' : primaryId,
131 position: chrome.system.display.LayoutPosition.RIGHT,
132 offset: 0
133 });
134 }
92 } 135 }
93 }; 136 };
94 137
95 return {FakeSystemDisplay: FakeSystemDisplay}; 138 return {FakeSystemDisplay: FakeSystemDisplay};
96 }); 139 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/settings/device_page_tests.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698