Index: chrome/test/data/extensions/api_test/instance_id/get_id/get_id.js |
diff --git a/chrome/test/data/extensions/api_test/instance_id/get_id/get_id.js b/chrome/test/data/extensions/api_test/instance_id/get_id/get_id.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..53bd36fd314e901ce09939e513335643887ed3c2 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/instance_id/get_id/get_id.js |
@@ -0,0 +1,53 @@ |
+// 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 getIDWithoutCallback() { |
+ try { |
+ chrome.instanceID.getID(); |
+ chrome.test.fail("Calling getID without callback should fail."); |
+ } catch (e) { |
+ chrome.test.succeed(); |
+ }; |
+} |
+ |
+function getIDWithCallback() { |
+ chrome.instanceID.getID(function(id) { |
+ if (chrome.runtime.lastError) { |
+ chrome.test.fail( |
+ "chrome.runtime.lastError: " + chrome.runtime.lastError.message); |
+ return; |
+ } |
+ if (id == "") { |
+ chrome.test.fail("Empty ID returned."); |
+ return; |
+ } |
+ |
+ chrome.test.succeed(); |
+ }); |
+} |
+ |
+var oldID; |
+function getIDTwice() { |
+ chrome.instanceID.getID(function(id) { |
+ if (!id) { |
+ chrome.test.fail("ID should not be zero."); |
+ return; |
+ } |
+ oldID = id; |
+ |
+ chrome.instanceID.getID(function(id) { |
+ if (!id || id != oldID) { |
+ chrome.test.fail("Same ID should be returned."); |
+ return; |
+ } |
+ chrome.test.succeed(); |
+ }); |
+ }); |
+} |
+ |
+chrome.test.runTests([ |
+ getIDWithoutCallback, |
+ getIDWithCallback, |
+ getIDTwice, |
+]); |