Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1707)

Unified Diff: appengine/config_service/ui/test/common/auth-signin_test.html

Issue 2981413002: config_service: Added tests for the auth-signin element (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/config_service/ui/test/index.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/config_service/ui/test/common/auth-signin_test.html
diff --git a/appengine/config_service/ui/test/common/auth-signin_test.html b/appengine/config_service/ui/test/common/auth-signin_test.html
new file mode 100644
index 0000000000000000000000000000000000000000..30fcf67d1e29d3266c13dcaede63d82aa7a9594d
--- /dev/null
+++ b/appengine/config_service/ui/test/common/auth-signin_test.html
@@ -0,0 +1,160 @@
+<!--
+ Copyright 2017 The LUCI Authors. All rights reserved.
+ Use of this source code is governed under the Apache License, Version 2.0
+ that can be found in the LICENSE file.
+-->
+
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
+
+ <title>auth-signin test</title>
+
+ <script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
+ <script src="../../bower_components/web-component-tester/browser.js"></script>
+
+ <link rel="import" href="../../src/config-ui/config-ui.html">
+ <link rel="import" href="../../common/auth-signin.html">
+ </head>
+ <body>
+
+ <test-fixture id="auth-signinTestFixture">
+ <template>
+ <auth-signin client_id="test-client-id"></auth-signin>
+ </template>
+ </test-fixture>
+
+ <script>
+
+ 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.
+ var auth_signin;
+ setup(function() {
+ auth_signin = fixture('auth-signinTestFixture');
+ });
+
+ test('checks that signed_in is false by default', function() {
+ expect(auth_signin.signed_in).to.be.false;
+ });
+
+ test('checks initialized is false before loading google-signin-aware', function() {
+ expect(auth_signin.initialized).to.be.false;
+ });
+
+ test('checks that auth-signin is never called without a client_id', function() {
+ 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.
+ });
+ });
+
+ 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.
+ var auth_signin;
+ var gapiWithUser;
+ var gapiWithoutUser;
+ var gapiWithoutAccessToken;
+ setup(function() {
+ auth_signin = fixture('auth-signinTestFixture');
+ gapiWithUser = {
+ "auth2": {
+ getAuthInstance: function() {
+ return {
+ "currentUser": {
+ get: function() {
+ return {
+ getAuthResponse: function () {
+ return {
+ "access_token": "test_token",
+ "token_type": "Bearer"
+ };
+ },
+ getBasicProfile: function() {
+ return {
+ getEmail: function() {
+ return "test@google.com";
+ },
+ getImageUrl: function() {
+ return "test.jpg";
+ }
+ };
+ }
+ };
+ }
+ }
+ };
+ }
+ }
+ };
+
+ gapiWithoutUser = {
+ "auth2": {
+ getAuthInstance: function() {
+ return {
+ "currentUser": {
+ get: function() {
+ return null;
+ }
+ }
+ };
+ }
+ }
+ };
+
+ gapiWithoutAccessToken = {
+ "auth2": {
+ getAuthInstance: function() {
+ return {
+ "currentUser": {
+ get: function() {
+ return {
+ getAuthResponse: function () {
+ return {
+ "access_token": null,
+ "token_type": null
+ };
+ },
+ };
+ }
+ }
+ };
+ }
+ }
+ };
+ });
+
+ test('fetch-configs is fired when gapi is initialized and user exists',
+ function () {
+ window.gapi = gapiWithUser;
+ auth_signin.initialized = true;
+ auth_signin.addEventListener('fetch-configs', function(done) {
+ expect(auth_signin.user).to.be.an('object');
+ expect(auth_signin.profile).to.be.an('object');
+ expect(auth_signin.auth_response).to.be.an('object');
+ expect(auth_signin.auth_headers).to.be.an('object');
+ done();
+ });
+ });
+
+ test('fetch-configs is fired when gapi is initialized and user does not exist',
+ function() {
+ window.gapi = gapiWithoutUser;
+ auth_signin.initialized = true;
+ auth_signin.addEventListener('fetch-configs', function(done) {
+ expect(auth_signin.user).to.be.null;
+ done();
+ });
+ });
+
+ test('fetch-configs is fired when gapi is initialized and user does not ' +
+ 'have access token', function() {
+ window.gapi = gapiWithoutAccessToken;
+ auth_signin.initialized = true;
+ auth_signin.addEventListener('fetch-configs', function(done) {
+ expect(auth_signin.user).to.be.an('object');
+ expect(auth_signin.user.getAuthResponse().access_token).to.be.null;
+ done();
+ })
+ });
+ });
+ </script>
+ </body>
+</html>
« no previous file with comments | « no previous file | appengine/config_service/ui/test/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698