1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5/** 6 * TestFixture for content settings exception area WebUI testing. 7 * @extends {testing.Test} 8 * @constructor 9 */ 10function ContentSettingsExceptionAreaWebUITest() {} 11 12ContentSettingsExceptionAreaWebUITest.prototype = { 13 __proto__: testing.Test.prototype, 14 15 /** @override */ 16 browsePreload: 'chrome://settings-frame/contentExceptions', 17}; 18 19GEN('#if defined(OS_CHROMEOS)'); 20GEN('#define MAYBE_testOpenContentSettingsExceptionArea ' + 21 'DISABLED_testOpenContentSettingsExceptionArea'); 22GEN('#else'); 23GEN('#define MAYBE_testOpenContentSettingsExceptionArea ' + 24 'testOpenContentSettingsExceptionArea'); 25GEN('#endif // defined(OS_CHROMEOS)'); 26// Test opening the content settings exception area has correct location. 27TEST_F('ContentSettingsExceptionAreaWebUITest', 28 'MAYBE_testOpenContentSettingsExceptionArea', function() { 29 assertEquals(this.browsePreload, document.location.href); 30}); 31 32/** 33 * A class to asynchronously test the content settings exception area dialog. 34 * @extends {testing.Test} 35 * @constructor 36 */ 37function ContentSettingsExceptionsAreaAsyncWebUITest() {} 38 39ContentSettingsExceptionsAreaAsyncWebUITest.prototype = { 40 __proto__: testing.Test.prototype, 41 42 /** @override */ 43 browsePreload: 'chrome://settings-frame/contentExceptions', 44 45 /** @override */ 46 isAsync: true, 47}; 48 49// Adds and removes a location content setting exception. 50TEST_F('ContentSettingsExceptionsAreaAsyncWebUITest', 51 'testAddRemoveLocationExceptions', function() { 52 assertEquals(this.browsePreload, document.location.href); 53 54 /** @const */ var origin = 'http://google.com:80'; 55 /** @const */ var setExceptions = ContentSettings.setExceptions; 56 57 var list = ContentSettings.getExceptionsList('cookies', 'normal'); 58 assertEquals(1, list.items.length); 59 60 var setExceptionsCounter = 0; 61 var setExceptionsCallback = function() { 62 setExceptionsCounter++; 63 if (setExceptionsCounter == 1) { 64 // The first item is now the exception (edit items are always last). 65 expectEquals('block', list.dataModel.item(0).setting); 66 expectEquals(origin, list.dataModel.item(0).origin); 67 68 // Delete the item and verify it worked. 69 list.deleteItemAtIndex(0); 70 } else if (setExceptionsCounter == 2) { 71 // Verify the item was deleted, restore the original method, and finish. 72 expectEquals(1, list.items.length); 73 ContentSettings.setExceptions = setExceptions; 74 testDone(); 75 } 76 }; 77 78 // NOTE: if this test doesn't succeed, |ContentSettings.setExceptions| may not 79 // be restored to its original method. I know no easy way to fix this. 80 ContentSettings.setExceptions = function() { 81 setExceptions.apply(ContentSettings, arguments); 82 setExceptionsCallback(); 83 }; 84 85 // Add an item to the location exception area to start the test. 86 list.items[0].finishEdit(origin, 'block'); 87}); 88