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

Side by Side Diff: extensions/test/data/web_view/apitest/main.js

Issue 615623002: Porting more tests to app_shell_browsertests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 6 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var embedder = {}; 5 var embedder = {};
6 6
7 // TODO(lfg) Move these functions to a common js. 7 // TODO(lfg) Move these functions to a common js.
8 window.runTest = function(testName) { 8 window.runTest = function(testName) {
9 if (!embedder.test.testList[testName]) { 9 if (!embedder.test.testList[testName]) {
10 window.console.warn('Incorrect testName: ' + testName); 10 window.console.warn('Incorrect testName: ' + testName);
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 try { 530 try {
531 webview.executeScript( 531 webview.executeScript(
532 {code: 'document.body.style.backgroundColor = "red";'}, 532 {code: 'document.body.style.backgroundColor = "red";'},
533 function(results) { embedder.test.fail(); }); 533 function(results) { embedder.test.fail(); });
534 } 534 }
535 catch (e) { 535 catch (e) {
536 embedder.test.succeed(); 536 embedder.test.succeed();
537 } 537 }
538 } 538 }
539 539
540 // This test verifies that the call of executeScript will fail and return null
541 // if the webview has been navigated to another source.
542 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() {
543 var webview = document.createElement('webview');
544 var initial = true;
545 var navigationOccur = false;
546 var newSrc = 'data:text/html,trigger navigation';
547 webview.addEventListener('loadstart', function() {
548 if (initial) {
549 webview.setAttribute('src', newSrc);
550 navigationOccur = true;
551 }
552 initial = false;
553 });
554 webview.addEventListener('loadstop', function() {
555 webview.executeScript(
556 {code:'document.body.style.backgroundColor = "red";'},
557 function(results) {
558 if (navigationOccur) {
559 // Expect a null results because the executeScript failed;
560 // return "red", otherwise.
561 embedder.test.assertEq(null, results);
562 embedder.test.succeed();
563 }
564 navigationOccur = false;
565 }
566 );
567 });
568 webview.setAttribute('src', "about:blank");
569 document.body.appendChild(webview);
570 }
571
572 function testFindAPI() {
573 var webview = new WebView();
574 webview.src = 'data:text/html,Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
575 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
576 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
577 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
578 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
579 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
580 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
581 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
582 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
583 'Dog dog dog Dog dog dogcatDog dogDogdog.<br><br>' +
584 '<a href="about:blank">Click here!</a>';
585
586 var loadstopListener2 = function(e) {
587 embedder.test.assertEq(webview.src, "about:blank");
588 embedder.test.succeed();
589 }
590
591 var loadstopListener1 = function(e) {
592 // Test find results.
593 webview.find("dog", {}, function(results) {
594 callbackTest = true;
595 embedder.test.assertEq(results.numberOfMatches, 100);
596 embedder.test.assertTrue(results.selectionRect.width > 0);
597 embedder.test.assertTrue(results.selectionRect.height > 0);
598
599 // Test finding next active matches.
600 webview.find("dog");
601 webview.find("dog");
602 webview.find("dog");
603 webview.find("dog");
604 webview.find("dog", {}, function(results) {
605 embedder.test.assertEq(results.activeMatchOrdinal, 6);
606 webview.find("dog", {backward: true});
607 webview.find("dog", {backward: true}, function(results) {
608 // Test the |backward| find option.
609 embedder.test.assertEq(results.activeMatchOrdinal, 4);
610
611 // Test the |matchCase| find option.
612 webview.find("Dog", {matchCase: true}, function(results) {
613 embedder.test.assertEq(results.numberOfMatches, 40);
614
615 // Test canceling find requests.
616 webview.find("dog");
617 webview.stopFinding();
618 webview.find("dog");
619 webview.find("cat");
620
621 // Test find results when looking for something that isn't there.
622 webview.find("fish", {}, function(results) {
623 embedder.test.assertEq(results.numberOfMatches, 0);
624 embedder.test.assertEq(results.activeMatchOrdinal, 0);
625 embedder.test.assertEq(results.selectionRect.left, 0);
626 embedder.test.assertEq(results.selectionRect.top, 0);
627 embedder.test.assertEq(results.selectionRect.width, 0);
628 embedder.test.assertEq(results.selectionRect.height, 0);
629
630 // Test following a link with stopFinding().
631 webview.removeEventListener('loadstop', loadstopListener1);
632 webview.addEventListener('loadstop', loadstopListener2);
633 webview.find("click here!", {}, function() {
634 webview.stopFinding("activate");
635 });
636 });
637 });
638 });
639 });
640 });
641 };
642
643 webview.addEventListener('loadstop', loadstopListener1);
644 document.body.appendChild(webview);
645 };
646
647 function testFindAPI_findupdate() {
648 var webview = new WebView();
649 webview.src = 'data:text/html,Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
650 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
651 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
652 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
653 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
654 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
655 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
656 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
657 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
658 'Dog dog dog Dog dog dogcatDog dogDogdog.<br><br>' +
659 '<a href="about:blank">Click here!</a>';
660 var canceledTest = false;
661 webview.addEventListener('loadstop', function(e) {
662 // Test the |findupdate| event.
663 webview.addEventListener('findupdate', function(e) {
664 if (e.activeMatchOrdinal > 0) {
665 // embedder.test.assertTrue(e.numberOfMatches >= e.activeMatchOrdinal)
666 // This currently fails because of http://crbug.com/342445 .
667 embedder.test.assertTrue(e.selectionRect.width > 0);
668 embedder.test.assertTrue(e.selectionRect.height > 0);
669 }
670
671 if (e.finalUpdate) {
672 if (e.canceled) {
673 canceledTest = true;
674 } else {
675 embedder.test.assertEq(e.searchText, "dog");
676 embedder.test.assertEq(e.numberOfMatches, 100);
677 embedder.test.assertEq(e.activeMatchOrdinal, 1);
678 embedder.test.assertTrue(canceledTest);
679 embedder.test.succeed();
680 }
681 }
682 });
683 wv.find("dog");
684 wv.find("cat");
685 wv.find("dog");
686 });
687
688 document.body.appendChild(webview);
689 };
690
691 // This test verifies that getProcessId is defined and returns a non-zero
692 // value corresponding to the processId of the guest process.
693 function testGetProcessId() {
694 var webview = document.createElement('webview');
695 webview.setAttribute('src', 'data:text/html,trigger navigation');
696 var firstLoad = function() {
697 webview.removeEventListener('loadstop', firstLoad);
698 embedder.test.assertTrue(webview.getProcessId() > 0);
699 embedder.test.succeed();
700 };
701 webview.addEventListener('loadstop', firstLoad);
702 document.body.appendChild(webview);
703 }
704
705 function testHiddenBeforeNavigation() {
706 var webview = document.createElement('webview');
707 webview.style.visibility = 'hidden';
708
709 var postMessageHandler = function(e) {
710 var data = JSON.parse(e.data);
711 window.removeEventListener('message', postMessageHandler);
712 if (data[0] == 'visibilityState-response') {
713 embedder.test.assertEq('hidden', data[1]);
714 embedder.test.succeed();
715 } else {
716 window.console.warn('Unexpected message: ' + data);
717 embedder.test.fail();
718 }
719 };
720
721 webview.addEventListener('loadstop', function(e) {
722 window.console.warn('webview.loadstop');
723 window.addEventListener('message', postMessageHandler);
724 webview.addEventListener('consolemessage', function(e) {
725 window.console.warn('g: ' + e.message);
726 });
727
728 webview.executeScript(
729 {file: 'inject_hidden_test.js'},
730 function(results) {
731 if (!results || !results.length) {
732 window.console.warn('Failed to inject script: inject_hidden_test.js');
733 embedder.test.fail();
734 return;
735 }
736
737 window.console.warn('script injection success');
738 webview.contentWindow.postMessage(
739 JSON.stringify(['visibilityState-request']), '*');
740 });
741 });
742
743 webview.setAttribute('src', 'data:text/html,<html><body></body></html>');
744 document.body.appendChild(webview);
745 }
746
747 // Makes sure inline scripts works inside guest that was loaded from
748 // accessible_resources.
749 function testInlineScriptFromAccessibleResources() {
750 var webview = document.createElement('webview');
751 // foobar is a privileged partition according to the manifest file.
752 webview.partition = 'foobar';
753 webview.addEventListener('loadabort', function(e) {
754 embedder.test.fail();
755 });
756 webview.addEventListener('consolemessage', function(e) {
757 window.console.log('consolemessage: ' + e.message);
758 if (e.message == 'guest_with_inline_script.html: Inline script ran') {
759 embedder.test.succeed();
760 }
761 });
762 webview.setAttribute('src', 'guest_with_inline_script.html');
763 document.body.appendChild(webview);
764 }
765
766 // This tests verifies that webview fires a loadabort event instead of crashing
767 // the browser if we attempt to navigate to a chrome-extension: URL with an
768 // extension ID that does not exist.
769 function testInvalidChromeExtensionURL() {
770 var invalidResource = 'chrome-extension://abc123/guest.html';
771 var webview = document.createElement('webview');
772 // foobar is a privileged partition according to the manifest file.
773 webview.partition = 'foobar';
774 webview.addEventListener('loadabort', function(e) {
775 embedder.test.succeed();
776 });
777 webview.setAttribute('src', invalidResource);
778 document.body.appendChild(webview);
779 }
780
540 // This test verifies that the loadabort event fires when loading a webview 781 // This test verifies that the loadabort event fires when loading a webview
541 // accessible resource from a partition that is not privileged. 782 // accessible resource from a partition that is not privileged.
542 function testLoadAbortChromeExtensionURLWrongPartition() { 783 function testLoadAbortChromeExtensionURLWrongPartition() {
543 var localResource = chrome.runtime.getURL('guest.html'); 784 var localResource = chrome.runtime.getURL('guest.html');
544 var webview = document.createElement('webview'); 785 var webview = document.createElement('webview');
545 webview.addEventListener('loadabort', function(e) { 786 webview.addEventListener('loadabort', function(e) {
546 embedder.test.assertEq('ERR_ADDRESS_UNREACHABLE', e.reason); 787 embedder.test.assertEq('ERR_ADDRESS_UNREACHABLE', e.reason);
547 embedder.test.succeed(); 788 embedder.test.succeed();
548 }); 789 });
549 webview.addEventListener('loadstop', function(e) { 790 webview.addEventListener('loadstop', function(e) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 'testAutosizeHeight': testAutosizeHeight, 896 'testAutosizeHeight': testAutosizeHeight,
656 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes, 897 'testAutosizeRemoveAttributes': testAutosizeRemoveAttributes,
657 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes, 898 'testAutosizeWithPartialAttributes': testAutosizeWithPartialAttributes,
658 'testCannotMutateEventName': testCannotMutateEventName, 899 'testCannotMutateEventName': testCannotMutateEventName,
659 'testContentLoadEvent': testContentLoadEvent, 900 'testContentLoadEvent': testContentLoadEvent,
660 'testDestroyOnEventListener': testDestroyOnEventListener, 901 'testDestroyOnEventListener': testDestroyOnEventListener,
661 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad, 902 'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad,
662 'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild, 903 'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild,
663 'testExecuteScript': testExecuteScript, 904 'testExecuteScript': testExecuteScript,
664 'testExecuteScriptFail': testExecuteScriptFail, 905 'testExecuteScriptFail': testExecuteScriptFail,
906 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged':
907 testExecuteScriptIsAbortedWhenWebViewSourceIsChanged,
908 'testFindAPI': testFindAPI,
909 'testFindAPI_findupdate': testFindAPI,
910 'testGetProcessId': testGetProcessId,
911 'testHiddenBeforeNavigation': testHiddenBeforeNavigation,
912 'testInlineScriptFromAccessibleResources':
913 testInlineScriptFromAccessibleResources,
914 'testInvalidChromeExtensionURL': testInvalidChromeExtensionURL,
665 'testLoadAbortChromeExtensionURLWrongPartition': 915 'testLoadAbortChromeExtensionURLWrongPartition':
666 testLoadAbortChromeExtensionURLWrongPartition, 916 testLoadAbortChromeExtensionURLWrongPartition,
667 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL, 917 'testLoadAbortIllegalChromeURL': testLoadAbortIllegalChromeURL,
668 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL, 918 'testLoadAbortIllegalFileURL': testLoadAbortIllegalFileURL,
669 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL, 919 'testLoadAbortIllegalJavaScriptURL': testLoadAbortIllegalJavaScriptURL,
670 'testLoadAbortInvalidNavigation': testLoadAbortInvalidNavigation, 920 'testLoadAbortInvalidNavigation': testLoadAbortInvalidNavigation,
671 'testLoadAbortNonWebSafeScheme': testLoadAbortNonWebSafeScheme, 921 'testLoadAbortNonWebSafeScheme': testLoadAbortNonWebSafeScheme,
672 'testLoadProgressEvent': testLoadProgressEvent 922 'testLoadProgressEvent': testLoadProgressEvent
673 }; 923 };
674 924
675 onload = function() { 925 onload = function() {
676 chrome.test.sendMessage('LAUNCHED'); 926 chrome.test.sendMessage('LAUNCHED');
677 }; 927 };
OLDNEW
« no previous file with comments | « extensions/test/data/web_view/apitest/inject_hidden_test.js ('k') | extensions/test/data/web_view/apitest/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698