From 00c8be997defd122486897faae3e09eb930f0f8d Mon Sep 17 00:00:00 2001 From: dtseng Date: Mon, 17 Aug 2015 16:35:47 -0700 Subject: [PATCH] Fix BackgroundTest.ShowContextMenu BUG=520938 Review URL: https://codereview.chromium.org/1287073008 Cr-Commit-Position: refs/heads/master@{#343774} --- .../cvox2/background/background_test.extjs | 38 ++++++++++++---------- .../testing/chromevox_next_e2e_test_base.js | 8 +++++ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/background_test.extjs b/chrome/browser/resources/chromeos/chromevox/cvox2/background/background_test.extjs index 6305e0db455f..a3b86067608b 100644 --- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/background_test.extjs +++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/background_test.extjs @@ -206,24 +206,6 @@ TEST_F('BackgroundTest', 'LiveRegionRemoveElement', function() { }); }); -// Test breaks because the context menu enters a nested message loop. -// http://crbug.com/520938 -TEST_F('BackgroundTest', 'DISABLED_ShowContextMenu', function() { - this.runWithLoadedTree(function() {/*! -

Document with link

- a - b - */}, - function(rootNode) { - this.mockTts.expectSpeech('a', this.doCmd('showContextMenu')); - this.mockTts.expectSpeech(' menu opened', this.newCallback()); - - var link = rootNode.find({role: chrome.automation.RoleType.link, - name: 'a'}); - link.focus(); - }); -}); - // Test fails because no speech is generated when the rootWebArea is // focused. // http://crbug.com/520940 @@ -246,3 +228,23 @@ TEST_F('BackgroundTest', 'AriaLabel', function() { } ); }); + +TEST_F('BackgroundTest', 'ShowContextMenu', function() { + this.runWithLoadedTree('a', + function(rootNode) { + cvox.ChromeVox.tts.expectSpeech(' menu opened', this.newCallback( + function() { + // When shown, the context menu pushes a new message loop so test + // messages sent to the browser do not get processed. Ensure we exit + // the context menu here. + go.showContextMenu(); + }) + ); + + var go = rootNode.find({ role: chrome.automation.RoleType.link }); + this.listenOnce(go, 'focus', function(e) { + this.doCmd('showContextMenu')(); + }.bind(this), true); + go.focus(); + }.bind(this)); +}); diff --git a/chrome/browser/resources/chromeos/chromevox/testing/chromevox_next_e2e_test_base.js b/chrome/browser/resources/chromeos/chromevox/testing/chromevox_next_e2e_test_base.js index db99b8ca8518..8822e31f4536 100644 --- a/chrome/browser/resources/chromeos/chromevox/testing/chromevox_next_e2e_test_base.js +++ b/chrome/browser/resources/chromeos/chromevox/testing/chromevox_next_e2e_test_base.js @@ -46,5 +46,13 @@ ChromeVoxNextE2ETest.prototype = { r.addEventListener('loadComplete', listener, true); this.runWithTab(doc); }.bind(this)); + }, + + listenOnce: function(node, eventType, callback, capture) { + var innerCallback = this.newCallback(function() { + node.removeEventListener(eventType, innerCallback, capture); + callback(); + }); + node.addEventListener(eventType, innerCallback, capture); } }; -- 2.11.4.GIT