Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!-- | |
| 2 Copyright 2017 The LUCI Authors. All rights reserved. | |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | |
| 4 that can be found in the LICENSE file. | |
| 5 --> | |
| 6 | |
| 7 <!doctype html> | |
| 8 <html lang="en"> | |
| 9 <head> | |
| 10 <meta charset="utf-8"> | |
| 11 <meta name="viewport" content="width=device-width, minimum-scale=1, initial- scale=1, user-scalable=yes"> | |
| 12 | |
| 13 <title>auth-signin test</title> | |
| 14 | |
| 15 <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js">< /script> | |
| 16 <script src="../../bower_components/web-component-tester/browser.js"></scrip t> | |
| 17 | |
| 18 <link rel="import" href="../../src/config-ui/config-ui.html"> | |
| 19 <link rel="import" href="../../common/auth-signin.html"> | |
| 20 </head> | |
| 21 <body> | |
| 22 | |
| 23 <test-fixture id="auth-signinTestFixture"> | |
| 24 <template> | |
| 25 <auth-signin client_id="test-client-id"></auth-signin> | |
| 26 </template> | |
| 27 </test-fixture> | |
| 28 | |
| 29 <script> | |
| 30 | |
| 31 suite('Default values', function() { | |
|
Sergey Berezin
2017/07/21 01:07:49
nit: I'd consider these values "initial", not "def
cwpayton
2017/07/21 16:34:59
Done.
| |
| 32 var auth_signin; | |
| 33 setup(function() { | |
| 34 auth_signin = fixture('auth-signinTestFixture'); | |
| 35 }); | |
| 36 | |
| 37 test('checks that signed_in is false by default', function() { | |
| 38 expect(auth_signin.signed_in).to.be.false; | |
| 39 }); | |
| 40 | |
| 41 test('checks initialized is false before loading google-signin-aware', f unction() { | |
| 42 expect(auth_signin.initialized).to.be.false; | |
| 43 }); | |
| 44 | |
| 45 test('checks that auth-signin is never called without a client_id', func tion() { | |
| 46 expect(auth_signin.client_id).to.not.be.null; | |
|
Sergey Berezin
2017/07/21 01:07:49
Technically, this test really checks that the clie
cwpayton
2017/07/21 16:34:59
Done.
| |
| 47 }); | |
| 48 }); | |
| 49 | |
| 50 suite('Initialized actions', function () { | |
|
Sergey Berezin
2017/07/21 01:07:49
How about this naming:
suite('fetch-configs alway
cwpayton
2017/07/21 16:34:59
Done.
| |
| 51 var auth_signin; | |
| 52 var gapiWithUser; | |
| 53 var gapiWithoutUser; | |
| 54 var gapiWithoutAccessToken; | |
| 55 setup(function() { | |
| 56 auth_signin = fixture('auth-signinTestFixture'); | |
| 57 gapiWithUser = { | |
| 58 "auth2": { | |
| 59 getAuthInstance: function() { | |
| 60 return { | |
| 61 "currentUser": { | |
| 62 get: function() { | |
| 63 return { | |
| 64 getAuthResponse: function () { | |
| 65 return { | |
| 66 "access_token": "test_token", | |
| 67 "token_type": "Bearer" | |
| 68 }; | |
| 69 }, | |
| 70 getBasicProfile: function() { | |
| 71 return { | |
| 72 getEmail: function() { | |
| 73 return "test@google.com"; | |
| 74 }, | |
| 75 getImageUrl: function() { | |
| 76 return "test.jpg"; | |
| 77 } | |
| 78 }; | |
| 79 } | |
| 80 }; | |
| 81 } | |
| 82 } | |
| 83 }; | |
| 84 } | |
| 85 } | |
| 86 }; | |
| 87 | |
| 88 gapiWithoutUser = { | |
| 89 "auth2": { | |
| 90 getAuthInstance: function() { | |
| 91 return { | |
| 92 "currentUser": { | |
| 93 get: function() { | |
| 94 return null; | |
| 95 } | |
| 96 } | |
| 97 }; | |
| 98 } | |
| 99 } | |
| 100 }; | |
| 101 | |
| 102 gapiWithoutAccessToken = { | |
| 103 "auth2": { | |
| 104 getAuthInstance: function() { | |
| 105 return { | |
| 106 "currentUser": { | |
| 107 get: function() { | |
| 108 return { | |
| 109 getAuthResponse: function () { | |
| 110 return { | |
| 111 "access_token": null, | |
| 112 "token_type": null | |
| 113 }; | |
| 114 }, | |
| 115 }; | |
| 116 } | |
| 117 } | |
| 118 }; | |
| 119 } | |
| 120 } | |
| 121 }; | |
| 122 }); | |
| 123 | |
| 124 test('fetch-configs is fired when gapi is initialized and user exists', | |
| 125 function () { | |
| 126 window.gapi = gapiWithUser; | |
| 127 auth_signin.initialized = true; | |
| 128 auth_signin.addEventListener('fetch-configs', function(done) { | |
| 129 expect(auth_signin.user).to.be.an('object'); | |
| 130 expect(auth_signin.profile).to.be.an('object'); | |
| 131 expect(auth_signin.auth_response).to.be.an('object'); | |
| 132 expect(auth_signin.auth_headers).to.be.an('object'); | |
| 133 done(); | |
| 134 }); | |
| 135 }); | |
| 136 | |
| 137 test('fetch-configs is fired when gapi is initialized and user does not exist', | |
| 138 function() { | |
| 139 window.gapi = gapiWithoutUser; | |
| 140 auth_signin.initialized = true; | |
| 141 auth_signin.addEventListener('fetch-configs', function(done) { | |
| 142 expect(auth_signin.user).to.be.null; | |
| 143 done(); | |
| 144 }); | |
| 145 }); | |
| 146 | |
| 147 test('fetch-configs is fired when gapi is initialized and user does not ' + | |
| 148 'have access token', function() { | |
| 149 window.gapi = gapiWithoutAccessToken; | |
| 150 auth_signin.initialized = true; | |
| 151 auth_signin.addEventListener('fetch-configs', function(done) { | |
| 152 expect(auth_signin.user).to.be.an('object'); | |
| 153 expect(auth_signin.user.getAuthResponse().access_token).to.be.null; | |
| 154 done(); | |
| 155 }) | |
| 156 }); | |
| 157 }); | |
| 158 </script> | |
| 159 </body> | |
| 160 </html> | |
| OLD | NEW |