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

Unified Diff: chrome/test/data/extensions/api_test/native_bindings/extension/background.js

Issue 2718543004: [Extensions Bindings] Add ChromeSetting custom type (Closed)
Patch Set: . Created 3 years, 10 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/native_bindings/extension/background.js
diff --git a/chrome/test/data/extensions/api_test/native_bindings/extension/background.js b/chrome/test/data/extensions/api_test/native_bindings/extension/background.js
index 0a401d518e647cf9d4d4c72cbdea3518642f3fd4..0689c8acfbc3923fad49b22d9482aea7f8fc6ffc 100644
--- a/chrome/test/data/extensions/api_test/native_bindings/extension/background.js
+++ b/chrome/test/data/extensions/api_test/native_bindings/extension/background.js
@@ -152,6 +152,56 @@ var tests = [
});
});
},
+ function testChromeSetting() {
+ chrome.test.assertTrue(!!chrome.privacy, 'privacy');
+ chrome.test.assertTrue(!!chrome.privacy.websites, 'websites');
+ var cookiePolicy = chrome.privacy.websites.thirdPartyCookiesAllowed;
+ chrome.test.assertTrue(!!cookiePolicy, 'cookie policy');
+ chrome.test.assertTrue(!!cookiePolicy.get, 'get');
+ chrome.test.assertTrue(!!cookiePolicy.set, 'set');
+ chrome.test.assertTrue(!!cookiePolicy.clear, 'clear');
+ chrome.test.assertTrue(!!cookiePolicy.onChange, 'onchange');
+
+ // The JSON spec for ChromeSettings is weird, because it claims it allows
+ // any type for <val> in ChromeSetting.set({value: <val>}), but this is just
+ // a hack in our schema generation because we curry in the different types
+ // of restrictions. Trying to pass in the wrong type for value should fail
+ // (synchronously).
+ var caught = false;
+ try {
+ cookiePolicy.set({value: 'not a bool'});
+ } catch (e) {
+ caught = true;
+ }
+ chrome.test.assertTrue(caught, 'caught');
+
+ var listenerPromise = new Promise((resolve, reject) => {
+ cookiePolicy.onChange.addListener(function listener(details) {
+ chrome.test.assertTrue(!!details, 'listener details');
+ chrome.test.assertEq(false, details.value);
+ cookiePolicy.onChange.removeListener(listener);
+ resolve();
+ });
+ });
+
+ var methodPromise = new Promise((resolve, reject) => {
+ cookiePolicy.get({}, (details) => {
+ chrome.test.assertTrue(!!details, 'get details');
+ chrome.test.assertTrue(details.value, 'details value true');
+ cookiePolicy.set({value: false}, () => {
+ cookiePolicy.get({}, (details) => {
+ chrome.test.assertTrue(!!details, 'get details');
+ chrome.test.assertFalse(details.value, 'details value false');
+ resolve();
+ });
+ });
+ });
+ });
+
+ Promise.all([listenerPromise, methodPromise]).then(() => {
+ chrome.test.succeed();
+ });
+ },
];
chrome.test.getConfig(config => {

Powered by Google App Engine
This is Rietveld 408576698