diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 01:43:02 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 01:43:02 +0000 |
commit | d13950ec676bc8aa9ea493e89a4cd1aee4a41913 (patch) | |
tree | 548e23868022937d34b2966a2e08f2a3d6510bbd /chrome/test | |
parent | f8c726650ef5fff6a9cc37411193c186a16f673f (diff) | |
download | chromium_src-d13950ec676bc8aa9ea493e89a4cd1aee4a41913.zip chromium_src-d13950ec676bc8aa9ea493e89a4cd1aee4a41913.tar.gz chromium_src-d13950ec676bc8aa9ea493e89a4cd1aee4a41913.tar.bz2 |
Add ExtensionsQuotaService to limit abusive amounts of requests
to mutating extension functions, as discussed on chromium-dev and
in Extensions quotaserver design doc.
Add a hook in the dispatcher to have the quota service assess the request.
Wire up bookmarks.{create, move, remove, update} to the service.
BUG=19899
TEST=ExtensionsQuotaServiceTest, QuotaLimitHeuristicTest (both new)
Review URL: http://codereview.chromium.org/441006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33770 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/data/extensions/api_test/bookmarks/test.js | 94 |
1 files changed, 72 insertions, 22 deletions
diff --git a/chrome/test/data/extensions/api_test/bookmarks/test.js b/chrome/test/data/extensions/api_test/bookmarks/test.js index 7f0a97a..eb32dcc 100644 --- a/chrome/test/data/extensions/api_test/bookmarks/test.js +++ b/chrome/test/data/extensions/api_test/bookmarks/test.js @@ -17,6 +17,12 @@ var node2 = {parentId:"1", title:"foo quux", url:"http://www.example.com/bar"}; var node3 = {parentId:"1", title:"bar baz", url:"http://www.google.com/hello/quux"}; +var quota_node1 = {parentId:"1", title:"Dave", + url:"http://www.dmband.com/"}; +var quota_node2 = {parentId:"1", title:"UW", + url:"http://www.uwaterloo.ca/"}; +var quota_node3 = {parentId:"1", title:"Whistler", + url:"http://www.whistlerblackcomb.com/"}; var pass = chrome.test.callbackPass; var fail = chrome.test.callbackFail; @@ -66,6 +72,30 @@ function compareTrees(left, right) { return true; } +function createThreeNodes(one, two, three) { + var bookmarks_bar = expected[0].children[0]; + chrome.bookmarks.create(one, pass(function(results) { + one.id = results.id; + one.index = results.index; + bookmarks_bar.children.push(one); + })); + chrome.bookmarks.create(two, pass(function(results) { + two.id = results.id; + two.index = results.index; + bookmarks_bar.children.push(two); + })); + chrome.bookmarks.create(three, pass(function(results) { + three.id = results.id; + three.index = results.index; + bookmarks_bar.children.push(three); + })); + chrome.bookmarks.getTree(pass(function(results) { + chrome.test.assertTrue(compareTrees(expected, results), + "getTree() result != expected"); + expected = results; + })); +} + chrome.test.runTests([ function getTree() { chrome.bookmarks.getTree(pass(function(results) { @@ -136,27 +166,7 @@ chrome.test.runTests([ }, function move_setup() { - var bookmarks_bar = expected[0].children[0]; - chrome.bookmarks.create(node1, pass(function(results) { - node1.id = results.id; - node1.index = results.index; - bookmarks_bar.children.push(node1); - })); - chrome.bookmarks.create(node2, pass(function(results) { - node2.id = results.id; - node2.index = results.index; - bookmarks_bar.children.push(node2); - })); - chrome.bookmarks.create(node3, pass(function(results) { - node3.id = results.id; - node3.index = results.index; - bookmarks_bar.children.push(node3); - })); - chrome.bookmarks.getTree(pass(function(results) { - chrome.test.assertTrue(compareTrees(expected, results), - "getTree() result != expected"); - expected = results; - })); + createThreeNodes(node1, node2, node3); }, function move() { @@ -280,7 +290,7 @@ chrome.test.runTests([ expected = results; })); }, - + function removeTree() { var parentId = node2.parentId; var folder = expected[0].children[1].children[0]; @@ -298,4 +308,44 @@ chrome.test.runTests([ expected = results; })); }, + + function quotaLimitedCreate() { + var node = {parentId:"1", title:"quotacreate", url:"http://www.quota.com/"}; + for (i = 0; i < 100; i++) { + chrome.bookmarks.create(node, pass(function(results) { + expected[0].children[0].children.push(results); + })); + } + chrome.bookmarks.create(node, + fail("This request exceeds available quota.")); + + chrome.test.resetQuota(); + + // Also, test that > 100 creations of different items is fine. + for (i = 0; i < 101; i++) { + var changer = {parentId:"1", title:"" + i, url:"http://www.quota.com/"}; + chrome.bookmarks.create(changer, pass(function(results) { + expected[0].children[0].children.push(results); + })); + } + }, + + function quota_setup() { + createThreeNodes(quota_node1, quota_node2, quota_node3); + }, + + function quotaLimitedUpdate() { + var title = "hello, world!"; + for (i = 0; i < 100; i++) { + chrome.bookmarks.update(quota_node1.id, {"title": title}, + pass(function(results) { + chrome.test.assertEq(title, results.title); + } + )); + } + chrome.bookmarks.update(quota_node1.id, {"title": title}, + fail("This request exceeds available quota.")); + + chrome.test.resetQuota(); + }, ]); |