Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / remoting / webapp / browser_test / update_pin_browser_test.js
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6  * @fileoverview
7  * @suppress {checkTypes}
8  * Browser test for the scenario below:
9  * 1. Change the PIN.
10  * 2. Connect with the new PIN.
11  * 3. Verify the connection succeeded.
12  * 4. Disconnect and reconnect with the old PIN.
13  * 5. Verify the connection failed.
14  */
15
16 'use strict';
17
18 /** @constructor */
19 browserTest.Update_PIN = function() {};
20
21 browserTest.Update_PIN.prototype.run = function(data) {
22   var LOGIN_BACKOFF_WAIT = 2000;
23   // Input validation
24   browserTest.expect(typeof data.new_pin == 'string');
25   browserTest.expect(typeof data.old_pin == 'string');
26   browserTest.expect(data.new_pin != data.old_pin,
27                      'The new PIN and the old PIN cannot be the same');
28
29   this.changePIN_(data.new_pin).then(
30     browserTest.connectMe2Me
31   ).then(function(){
32     return browserTest.enterPIN(data.old_pin, true /* expectError*/);
33   }).then(
34     // Sleep for two seconds to allow for the login backoff logic to reset.
35     base.Promise.sleep.bind(null, LOGIN_BACKOFF_WAIT)
36   ).then(
37     browserTest.connectMe2Me
38   ).then(function(){
39     return browserTest.enterPIN_(data.new_pin, false /* expectError*/)
40   }).then(
41     // Clean up the test by disconnecting and changing the PIN back
42     browserTest.disconnect
43   ).then(
44     // The PIN must be restored regardless of success or failure.
45     this.changePIN_.bind(this, data.old_pin),
46     this.changePIN_.bind(this, data.old_pin)
47   ).then(
48     // On fulfilled.
49     browserTest.pass,
50     // On rejected.
51     browserTest.fail
52   );
53 };
54
55 browserTest.Update_PIN.prototype.changePIN_ = function(newPin) {
56   var AppMode = remoting.AppMode;
57   var HOST_RESTART_WAIT = 10000;
58   browserTest.clickOnControl('change-daemon-pin');
59   return browserTest.setupPIN(newPin);
60 };