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.
5 var checkSrc = function(element, expectedValue) {
6 // Note that element.getAttribute('src') should not be used, it can be out of
7 // sync with element.src.
8 chrome.test.assertEq(expectedValue, element.src);
12 chrome.test.runTests([
14 var expectedSrcOne = 'data:text/html,<body>One</body>';
15 var expectedSrcTwo = 'data:text/html,<body>Two</body>';
16 var expectedSrcThree = 'data:text/html,<body>Three</body>';
19 // For setting src, we check if both webview.setAttribute('src', ?);
20 // and webview.src = ?; works properly.
21 var webview = document.querySelector('webview');
23 var runStep2 = function() {
25 chrome.test.log('run step: ' + step);
26 // Check if initial src is set correctly.
27 checkSrc(webview, expectedSrcOne);
28 webview.setAttribute('src', expectedSrcTwo);
31 var runStep3 = function() {
33 chrome.test.log('run step: ' + step);
34 // Expect the src change to be reflected.
35 checkSrc(webview, expectedSrcTwo);
36 // Set src attribute directly on the element.
37 webview.src = expectedSrcThree;
40 var runStep4 = function() {
42 chrome.test.log('run step: ' + step);
43 // Expect the src change to be reflected.
44 checkSrc(webview, expectedSrcThree);
45 // Set empty src, this will be ignored.
46 webview.setAttribute('src', '');
48 setTimeout(function() {
49 // Expect empty src to be ignored.
50 checkSrc(webview, expectedSrcThree);
51 // Set empty src again, directly changing the src attribute.
54 setTimeout(function() {
55 // Expect empty src to be ignored.
56 checkSrc(webview, expectedSrcThree);
57 chrome.test.succeed();
62 // Wait for navigation to complete before checking src attribute.
63 webview.addEventListener('loadcommit', function(e) {
76 chrome.test.fail('Unexpected step: ' + step + ' with url: ' +