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

Unified Diff: chrome/test/data/extensions/api_test/instance_id/get_token/get_token.js

Issue 1128123003: Implement InstanceID API functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test Created 5 years, 7 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
Index: chrome/test/data/extensions/api_test/instance_id/get_token/get_token.js
diff --git a/chrome/test/data/extensions/api_test/instance_id/get_token/get_token.js b/chrome/test/data/extensions/api_test/instance_id/get_token/get_token.js
new file mode 100644
index 0000000000000000000000000000000000000000..7a0a1c997c1a302cc59d08feb550049acd551012
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/instance_id/get_token/get_token.js
@@ -0,0 +1,133 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function getTokenWithoutParameters() {
+ try {
+ chrome.instanceID.getToken();
+ chrome.test.fail(
+ "Calling getToken without parameters should fail.");
+ } catch (e) {
+ chrome.test.succeed();
+ };
+}
+
+function getTokenWithoutCallback() {
+ try {
+ chrome.instanceID.getToken({"authorizedEntity": "1", "scope": "GCM"});
+ chrome.test.fail(
+ "Calling getToken without callback should fail.");
+ } catch (e) {
+ chrome.test.succeed();
+ };
+}
+
+function getTokenWithoutAuthorizedEntity() {
+ try {
+ chrome.instanceID.getToken({"scope": "GCM"});
+ chrome.test.fail(
+ "Calling getToken without authorizedEntity parameter should fail.");
+ } catch (e) {
+ chrome.test.succeed();
+ };
+}
+
+function getTokenWithInvalidAuthorizedEntity() {
+ try {
+ chrome.instanceID.getToken({"authorizedEntity": 1, "scope": "GCM"});
+ chrome.test.fail(
+ "Calling getToken with invalid authorizedEntity parameter " +
+ "should fail.");
+ } catch (e) {
+ chrome.test.succeed();
+ };
+}
+
+function getTokenWithoutScope() {
+ try {
+ chrome.instanceID.getToken({"authorizedEntity": "1"});
+ chrome.test.fail(
+ "Calling getToken without scope parameter should fail.");
+ } catch (e) {
+ chrome.test.succeed();
+ };
+}
+
+function getTokenWithInvalidScope() {
+ try {
+ chrome.instanceID.getToken({"authorizedEntity": "1", "scope": 1});
+ chrome.test.fail(
+ "Calling getToken with invalid scope parameter should fail.");
+ } catch (e) {
+ chrome.test.succeed();
+ };
+}
+
+function getTokenWithInvalidOptionValue() {
+ try {
+ chrome.instanceID.getToken(
+ {"authorizedEntity": "1", "scope": "GCM", "options": {"foo": 1}},
+ function(token) {
+ if (chrome.runtime.lastError) {
+ chrome.test.succeed();
+ return;
+ }
+ chrome.test.fail(
+ "Calling getToken with invalid option value should fail.");
+ }
+ );
+ } catch (e) {
+ chrome.test.succeed();
+ };
+}
+
+function getTokenWithoutOptions() {
+ chrome.instanceID.getToken(
+ {"authorizedEntity": "1", "scope": "GCM"},
+ function(token) {
+ if (chrome.runtime.lastError) {
+ chrome.test.fail(
+ "chrome.runtime.lastError: " + chrome.runtime.lastError.message);
+ return;
+ }
+ if (!token) {
+ chrome.test.fail("Empty token returned.");
+ return;
+ }
+
+ chrome.test.succeed();
+ }
+ );
+}
+
+function getTokenWithValidOptions() {
+ chrome.instanceID.getToken(
+ {"authorizedEntity": "1", "scope": "GCM", "options": {"foo": "1"}},
+ function(token) {
+ if (chrome.runtime.lastError) {
+ chrome.test.fail(
+ "chrome.runtime.lastError: " + chrome.runtime.lastError.message);
+ return;
+ }
+ if (!token) {
+ chrome.test.fail("Empty token returned.");
+ return;
+ }
+
+ chrome.test.succeed();
+ }
+ );
+}
+
+chrome.test.runTests([
+ getTokenWithoutParameters,
+ getTokenWithoutCallback,
+ getTokenWithoutAuthorizedEntity,
+ getTokenWithInvalidAuthorizedEntity,
+ getTokenWithoutScope,
+ getTokenWithInvalidScope,
+ getTokenWithInvalidOptionValue,
+ // TODO(jianli): To be enabled when GetToken is implemented.
+ //getTokenWithoutOptions,
+ //getTokenWithValidOptions,
+]);

Powered by Google App Engine
This is Rietveld 408576698