summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-01 21:11:42 +0000
committerjamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-01 21:11:42 +0000
commit3c254b86ec4c6ad714f7c2cb3eec768765b0098d (patch)
tree25c1460d67c7648ce30610764d1aa9da8241de0e
parent01188669a2b154818e5db03cc36fb2dd23b8d947 (diff)
downloadchromium_src-3c254b86ec4c6ad714f7c2cb3eec768765b0098d.zip
chromium_src-3c254b86ec4c6ad714f7c2cb3eec768765b0098d.tar.gz
chromium_src-3c254b86ec4c6ad714f7c2cb3eec768765b0098d.tar.bz2
Refactor JS browser tests.
Move the common methods from the existing PIN tests into browser_test.js and add expectEvent. Review URL: https://codereview.chromium.org/429413002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287088 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/webapp/browser_test/browser_test.js49
-rw-r--r--remoting/webapp/browser_test/cancel_pin_browser_test.js14
-rw-r--r--remoting/webapp/browser_test/invalid_pin_browser_test.js12
-rw-r--r--remoting/webapp/browser_test/update_pin_browser_test.js47
4 files changed, 64 insertions, 58 deletions
diff --git a/remoting/webapp/browser_test/browser_test.js b/remoting/webapp/browser_test/browser_test.js
index e0ff0b2..4785175 100644
--- a/remoting/webapp/browser_test/browser_test.js
+++ b/remoting/webapp/browser_test/browser_test.js
@@ -167,10 +167,38 @@ browserTest.connectMe2Me = function() {
// On time out.
return Promise.resolve();
}).then(function() {
- return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT);
+ return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000);
});
};
+browserTest.disconnect = function() {
+ var AppMode = remoting.AppMode;
+ remoting.disconnect();
+ return browserTest.onUIMode(AppMode.CLIENT_SESSION_FINISHED_ME2ME).then(
+ function() {
+ browserTest.clickOnControl('client-finished-me2me-button');
+ return browserTest.onUIMode(AppMode.HOME);
+ });
+};
+
+browserTest.enterPIN = function(pin, opt_expectError) {
+ // Wait for 500ms before hitting the PIN button. From experiment, sometimes
+ // the PIN prompt does not dismiss without the timeout.
+ var CONNECT_PIN_WAIT = 500;
+
+ document.getElementById('pin-entry').value = pin;
+
+ return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() {
+ browserTest.clickOnControl('pin-connect-button');
+ }).then(function() {
+ if (opt_expectError) {
+ return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE);
+ } else {
+ return browserTest.expectMe2MeConnected();
+ }
+ });
+};
+
browserTest.expectMe2MeError = function(errorTag) {
var AppMode = remoting.AppMode;
var Timeout = browserTest.Timeout;
@@ -215,6 +243,25 @@ browserTest.expectMe2MeConnected = function() {
return Promise.race([onConnected, onFailure]);
};
+browserTest.expectEvent = function(eventSource, event, timeoutMs,
+ opt_expectedData) {
+ return new Promise(function(fullfil, reject) {
+ var verifyEventParameters = function(actualData) {
+ if (opt_expectedData === undefined || opt_expectedData === actualData) {
+ fullfil();
+ } else {
+ reject('Bad event data; expected ' + opt_expectedData +
+ '; got ' + actualData);
+ }
+ };
+ eventSource.addEventListener(event, verifyEventParameters);
+ base.Promise.sleep(timeoutMs).then(function() {
+ reject(Error('Event ' + event + ' not received after ' +
+ timeoutMs + 'ms.'));
+ });
+ });
+};
+
browserTest.runTest = function(testClass, data) {
try {
var test = new testClass();
diff --git a/remoting/webapp/browser_test/cancel_pin_browser_test.js b/remoting/webapp/browser_test/cancel_pin_browser_test.js
index b388936..507e986 100644
--- a/remoting/webapp/browser_test/cancel_pin_browser_test.js
+++ b/remoting/webapp/browser_test/cancel_pin_browser_test.js
@@ -26,19 +26,13 @@ browserTest.Cancel_PIN.prototype.run = function(data) {
return browserTest.onUIMode(AppMode.HOME);
}).then(function() {
return browserTest.connectMe2Me()
- }).then(
- this.enterPin_.bind(this, data.pin)
- ).then(function() {
+ }).then(function() {
+ return browserTest.enterPIN(data.pin)
+ }).then(function() {
// On fulfilled.
browserTest.pass();
}, function(reason) {
// On rejected.
browserTest.fail(reason);
});
-};
-
-browserTest.Cancel_PIN.prototype.enterPin_ = function(pin) {
- document.getElementById('pin-entry').value = pin;
- browserTest.clickOnControl('pin-connect-button');
- return browserTest.expectMe2MeConnected();
-};
+}; \ No newline at end of file
diff --git a/remoting/webapp/browser_test/invalid_pin_browser_test.js b/remoting/webapp/browser_test/invalid_pin_browser_test.js
index 480a7e8..f7a5935 100644
--- a/remoting/webapp/browser_test/invalid_pin_browser_test.js
+++ b/remoting/webapp/browser_test/invalid_pin_browser_test.js
@@ -21,9 +21,9 @@ browserTest.Invalid_PIN.prototype.run = function(data) {
browserTest.expect(typeof data.pin == 'string');
// Connect to me2me Host.
- browserTest.connectMe2Me().then(
- this.enterPIN_.bind(this, data.pin)
- ).then(
+ browserTest.connectMe2Me().then(function(){
+ return browserTest.enterPIN(data.pin, true)
+ }).then(
// Sleep for two seconds to allow the host backoff timer to reset.
base.Promise.sleep.bind(window, 2000)
).then(function() {
@@ -34,9 +34,3 @@ browserTest.Invalid_PIN.prototype.run = function(data) {
browserTest.fail(reason);
});
};
-
-browserTest.Invalid_PIN.prototype.enterPIN_ = function(pin) {
- document.getElementById('pin-entry').value = pin;
- browserTest.clickOnControl('pin-connect-button');
- return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE);
-};
diff --git a/remoting/webapp/browser_test/update_pin_browser_test.js b/remoting/webapp/browser_test/update_pin_browser_test.js
index 72cc8bf..370ed1f 100644
--- a/remoting/webapp/browser_test/update_pin_browser_test.js
+++ b/remoting/webapp/browser_test/update_pin_browser_test.js
@@ -28,18 +28,18 @@ browserTest.Update_PIN.prototype.run = function(data) {
this.changePIN_(data.new_pin).then(
browserTest.connectMe2Me
- ).then(
- this.enterPIN_.bind(this, data.old_pin, true /* expectError*/)
- ).then(
+ ).then(function(){
+ return browserTest.enterPIN(data.old_pin, true /* expectError*/);
+ }).then(
// Sleep for two seconds to allow for the login backoff logic to reset.
base.Promise.sleep.bind(null, LOGIN_BACKOFF_WAIT)
).then(
browserTest.connectMe2Me
- ).then(
- this.enterPIN_.bind(this, data.new_pin, false /* expectError*/)
- ).then(
+ ).then(function(){
+ return browserTest.enterPIN_(data.new_pin, false /* expectError*/)
+ }).then(
// Clean up the test by disconnecting and changing the PIN back
- this.disconnect_.bind(this)
+ browserTest.disconnect
).then(
// The PIN must be restored regardless of success or failure.
this.changePIN_.bind(this, data.old_pin),
@@ -53,37 +53,8 @@ browserTest.Update_PIN.prototype.run = function(data) {
};
browserTest.Update_PIN.prototype.changePIN_ = function(newPin) {
+ var AppMode = remoting.AppMode;
+ var HOST_RESTART_WAIT = 10000;
browserTest.clickOnControl('change-daemon-pin');
return browserTest.setupPIN(newPin);
};
-
-browserTest.Update_PIN.prototype.disconnect_ = function() {
- var AppMode = remoting.AppMode;
-
- remoting.disconnect();
-
- return browserTest.onUIMode(AppMode.CLIENT_SESSION_FINISHED_ME2ME)
- .then(function() {
- var onHome = browserTest.onUIMode(AppMode.HOME);
- browserTest.clickOnControl('client-finished-me2me-button');
- return onHome;
- });
-};
-
-browserTest.Update_PIN.prototype.enterPIN_ = function(pin, expectError) {
- // Wait for 500ms before hitting the PIN button. From experiment, sometimes
- // the PIN prompt does not dismiss without the timeout.
- var CONNECT_PIN_WAIT = 500;
-
- document.getElementById('pin-entry').value = pin;
-
- return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() {
- browserTest.clickOnControl('pin-connect-button');
- }).then(function() {
- if (expectError) {
- return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE);
- } else {
- return browserTest.expectMe2MeConnected();
- }
- });
-};