Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / webapp / browser_test / unauthenticated_browser_test.js
blobe08ee8245ab8e906af64fc5a18a9f7deac686745
1 // Copyright 2015 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.
5 /**
6  * @fileoverview
7  * @suppress {checkTypes}
8  *
9  * Browser test to verify that an unauthenticated state is handled correctly
10  * in the following situations:
11  * 1. When launching the app.
12  * 2. When refreshing the host-list.
13  *
14  * TODO(jamiewalch): Add a test case for connecting to a host.
15  */
17 'use strict';
19 /** @constructor */
20 browserTest.Unauthenticated = function() {
23 browserTest.Unauthenticated.prototype.run = function(data) {
24   remoting.MockIdentity.setActive(true);
25   remoting.MockHostListApi.setActive(true);
26   remoting.MockOAuth2Api.setActive(true);
27   remoting.mockIdentity.setAccessToken(
28       remoting.MockIdentity.AccessToken.NONE);
29   remoting.startDesktopRemoting();
31   browserTest.waitFor(
32       browserTest.isVisible('auth-button')
33   ).then(
34       this.restoreSignedInState.bind(this)
35   ).then(
36       function() {
37         console.log('waiting for enabled');
38         return browserTest.waitFor(browserTest.isEnabled('get-started-me2me'));
39       }
40   ).then(
41       // Show the Me2Me UI, invalidate the access token again, and refresh the
42       // host-list to verify that the user is prompted to sign in again.
43       function() {
44         console.log('clicking get-started-me2me');
45         browserTest.clickOnControl('get-started-me2me');
46         remoting.mockIdentity.setAccessToken(
47             remoting.MockIdentity.AccessToken.INVALID);
48         browserTest.clickOnControl('host-list-reload');
49         return browserTest.waitFor(
50             browserTest.isVisible('host-list-refresh-failed-button'));
51       }
52   ).then(
53       this.restoreSignedInState.bind(this)
54       // TODO(jamiewalch): The sign-in button of the host-list doesn't work
55       // for apps v2, because it assumes the v1 sign-in flow. Fix this and
56       // extend this test to handle an authentication failure at this point.
57   ).then(browserTest.pass, browserTest.fail);
60 // Set a valid access token, then re-authenticate. Note that we're not
61 // trying to test the sign-in flow here (that's tested elsewhere), we're
62 // just getting the app back into a signed-in state so that we can continue
63 // to test its behaviour if the token becomes invalid at various stages.
64 browserTest.Unauthenticated.prototype.restoreSignedInState = function() {
65   remoting.mockIdentity.setAccessToken(
66       remoting.MockIdentity.AccessToken.VALID);
67   browserTest.clickOnControl('auth-button');
68   return Promise.resolve();