| 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('auth-signin initial values are as expected', function() { |
| 32 var auth_signin; |
| 33 setup(function() { |
| 34 auth_signin = fixture('auth-signinTestFixture'); |
| 35 }); |
| 36 |
| 37 test('signed_in is false', function() { |
| 38 expect(auth_signin.signed_in).to.be.false; |
| 39 }); |
| 40 |
| 41 test('initialized is false', function() { |
| 42 expect(auth_signin.initialized).to.be.false; |
| 43 }); |
| 44 |
| 45 test('client_id is always present', function() { |
| 46 expect(auth_signin.client_id).to.be.equal('test-client-id'); |
| 47 }); |
| 48 }); |
| 49 |
| 50 suite('fetch-configs always fired when gapi is initialized', function () { |
| 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('when user exists', function() { |
| 125 window.gapi = gapiWithUser; |
| 126 auth_signin.initialized = true; |
| 127 auth_signin.addEventListener('fetch-configs', function(done) { |
| 128 expect(auth_signin.user).to.be.an('object'); |
| 129 expect(auth_signin.profile).to.be.an('object'); |
| 130 expect(auth_signin.auth_response).to.be.an('object'); |
| 131 expect(auth_signin.auth_headers).to.be.an('object'); |
| 132 done(); |
| 133 }); |
| 134 }); |
| 135 |
| 136 test('when user does not exist', function() { |
| 137 window.gapi = gapiWithoutUser; |
| 138 auth_signin.initialized = true; |
| 139 auth_signin.addEventListener('fetch-configs', function(done) { |
| 140 expect(auth_signin.user).to.be.null; |
| 141 done(); |
| 142 }); |
| 143 }); |
| 144 |
| 145 test('when user does not have access token', function() { |
| 146 window.gapi = gapiWithoutAccessToken; |
| 147 auth_signin.initialized = true; |
| 148 auth_signin.addEventListener('fetch-configs', function(done) { |
| 149 expect(auth_signin.user).to.be.an('object'); |
| 150 expect(auth_signin.user.getAuthResponse().access_token).to.be.null; |
| 151 done(); |
| 152 }) |
| 153 }); |
| 154 }); |
| 155 </script> |
| 156 </body> |
| 157 </html> |
| OLD | NEW |