Commit 0cf4b340 authored by Scott Chen's avatar Scott Chen Committed by Commit Bot

WebUI: fix flaky cr-action-menu test.

Bug: 812947
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: If2a653a7784b464d44bbde72d42df0ca719c2e90
Reviewed-on: https://chromium-review.googlesource.com/923580Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Scott Chen <scottchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537477}
parent e3e837b2
...@@ -306,42 +306,45 @@ suite('CrActionMenu', function() { ...@@ -306,42 +306,45 @@ suite('CrActionMenu', function() {
}); });
test('[auto-reposition] enables repositioning if content changes', function() { test(
menu.autoReposition = true; '[auto-reposition] enables repositioning if content changes',
function(done) {
dots.style.marginLeft = '800px'; menu.autoReposition = true;
let dotsRect = dots.getBoundingClientRect(); dots.style.marginLeft = '800px';
// Anchored at right-top by default. let dotsRect = dots.getBoundingClientRect();
menu.showAt(dots);
assertTrue(menu.open); // Anchored at right-top by default.
let menuRect = menu.getBoundingClientRect(); menu.showAt(dots);
assertEquals( assertTrue(menu.open);
Math.round(dotsRect.left + dotsRect.width), let menuRect = menu.getBoundingClientRect();
Math.round(menuRect.left + menuRect.width)); assertEquals(
assertEquals(dotsRect.top, menuRect.top); Math.round(dotsRect.left + dotsRect.width),
Math.round(menuRect.left + menuRect.width));
const lastMenuLeft = menuRect.left; assertEquals(dotsRect.top, menuRect.top);
const lastMenuWidth = menuRect.width;
const lastMenuLeft = menuRect.left;
// Still anchored at the right place after content size changes. const lastMenuWidth = menuRect.width;
items[0].textContent = 'this is a long string to make menu wide';
// Flush to wait for resizeObeserver's cycle. menu.addEventListener('cr-action-menu-repositioned', () => {
return PolymerTest.flushTasks().then(() => { assertTrue(menu.open);
assertTrue(menu.open); menuRect = menu.getBoundingClientRect();
menuRect = menu.getBoundingClientRect(); // Test that menu width got larger.
// Test that menu width got larger. assertTrue(menuRect.width > lastMenuWidth);
assertTrue(menuRect.width > lastMenuWidth); // Test that menu upper-left moved further left.
// Test that menu upper-left moved further left. assertTrue(menuRect.left < lastMenuLeft);
assertTrue(menuRect.left < lastMenuLeft); // Test that right and top did not move since it is anchored there.
// Test that right and top did not move since it is anchored there. assertEquals(
assertEquals( Math.round(dotsRect.left + dotsRect.width),
Math.round(dotsRect.left + dotsRect.width), Math.round(menuRect.left + menuRect.width));
Math.round(menuRect.left + menuRect.width)); assertEquals(dotsRect.top, menuRect.top);
assertEquals(dotsRect.top, menuRect.top); done();
}); });
});
// Still anchored at the right place after content size changes.
items[0].textContent = 'this is a long string to make menu wide';
});
suite('offscreen scroll positioning', function() { suite('offscreen scroll positioning', function() {
const bodyHeight = 10000; const bodyHeight = 10000;
......
...@@ -440,8 +440,10 @@ Polymer({ ...@@ -440,8 +440,10 @@ Polymer({
if (this.autoReposition) { if (this.autoReposition) {
this.resizeObserver_ = new ResizeObserver(() => { this.resizeObserver_ = new ResizeObserver(() => {
if (this.lastConfig_) if (this.lastConfig_) {
this.positionDialog_(this.lastConfig_); this.positionDialog_(this.lastConfig_);
this.fire('cr-action-menu-repositioned'); // For easier testing.
}
}); });
this.resizeObserver_.observe(this); this.resizeObserver_.observe(this);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment