| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 library browser; | 4 library browser; |
| 5 | 5 |
| 6 import "dart:async"; | 6 import "dart:async"; |
| 7 import "dart:convert" show UTF8, JSON; | 7 import "dart:convert" show UTF8, JSON; |
| 8 import "dart:core"; | 8 import "dart:core"; |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 import "dart:math" show min; | 10 import "dart:math" show min; |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 .write('Android device id: ${_adbDevice.deviceId}\n'); | 692 .write('Android device id: ${_adbDevice.deviceId}\n'); |
| 693 } | 693 } |
| 694 | 694 |
| 695 String toString() => _config.name; | 695 String toString() => _config.name; |
| 696 } | 696 } |
| 697 | 697 |
| 698 class AndroidChrome extends Browser { | 698 class AndroidChrome extends Browser { |
| 699 static const String viewAction = 'android.intent.action.VIEW'; | 699 static const String viewAction = 'android.intent.action.VIEW'; |
| 700 static const String mainAction = 'android.intent.action.MAIN'; | 700 static const String mainAction = 'android.intent.action.MAIN'; |
| 701 static const String chromePackage = 'com.android.chrome'; | 701 static const String chromePackage = 'com.android.chrome'; |
| 702 static const String chromeActivity = '.Main'; |
| 702 static const String browserPackage = 'com.android.browser'; | 703 static const String browserPackage = 'com.android.browser'; |
| 704 static const String browserActivity = '.BrowserActivity'; |
| 703 static const String firefoxPackage = 'org.mozilla.firefox'; | 705 static const String firefoxPackage = 'org.mozilla.firefox'; |
| 706 static const String firefoxActivity = '.App'; |
| 704 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; | 707 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; |
| 708 static const String turnScreenOnActivity = '.Main'; |
| 705 | 709 |
| 706 AdbDevice _adbDevice; | 710 AdbDevice _adbDevice; |
| 707 | 711 |
| 708 AndroidChrome(this._adbDevice); | 712 AndroidChrome(this._adbDevice); |
| 709 | 713 |
| 710 Future<bool> start(String url) { | 714 Future<bool> start(String url) { |
| 711 var browserIntent = | 715 var chromeIntent = |
| 712 new Intent(viewAction, browserPackage, '.BrowserActivity', url); | 716 new Intent(viewAction, chromePackage, chromeActivity, url); |
| 713 var chromeIntent = new Intent(viewAction, chromePackage, '.Main', url); | |
| 714 var firefoxIntent = new Intent(viewAction, firefoxPackage, '.App', url); | |
| 715 var turnScreenOnIntent = | 717 var turnScreenOnIntent = |
| 716 new Intent(mainAction, turnScreenOnPackage, '.Main'); | 718 new Intent(mainAction, turnScreenOnPackage, turnScreenOnActivity); |
| 717 | 719 |
| 718 var testing_resources_dir = | 720 var testing_resources_dir = |
| 719 new Path('third_party/android_testing_resources'); | 721 new Path('third_party/android_testing_resources'); |
| 720 if (!new Directory(testing_resources_dir.toNativePath()).existsSync()) { | 722 if (!new Directory(testing_resources_dir.toNativePath()).existsSync()) { |
| 721 DebugLogger.error("$testing_resources_dir doesn't exist. Exiting now."); | 723 DebugLogger.error("$testing_resources_dir doesn't exist. Exiting now."); |
| 722 exit(1); | 724 exit(1); |
| 723 } | 725 } |
| 724 | 726 |
| 725 var chromeAPK = testing_resources_dir.append('com.android.chrome-1.apk'); | 727 var chromeAPK = testing_resources_dir.append('com.android.chrome-1.apk'); |
| 726 var turnScreenOnAPK = testing_resources_dir.append('TurnScreenOn.apk'); | 728 var turnScreenOnAPK = testing_resources_dir.append('TurnScreenOn.apk'); |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 var embedded_iframe_div = document.getElementById('embedded_iframe_div'); | 1546 var embedded_iframe_div = document.getElementById('embedded_iframe_div'); |
| 1545 var embedded_iframe = document.getElementById('embedded_iframe'); | 1547 var embedded_iframe = document.getElementById('embedded_iframe'); |
| 1546 var number_div = document.getElementById('number'); | 1548 var number_div = document.getElementById('number'); |
| 1547 var executing_div = document.getElementById('currently_executing'); | 1549 var executing_div = document.getElementById('currently_executing'); |
| 1548 var error_div = document.getElementById('unhandled_error'); | 1550 var error_div = document.getElementById('unhandled_error'); |
| 1549 var use_iframe = ${useIframe}; | 1551 var use_iframe = ${useIframe}; |
| 1550 var start = new Date(); | 1552 var start = new Date(); |
| 1551 | 1553 |
| 1552 // Object that holds the state of an HTML test | 1554 // Object that holds the state of an HTML test |
| 1553 var html_test; | 1555 var html_test; |
| 1554 | 1556 |
| 1555 function newTaskHandler() { | 1557 function newTaskHandler() { |
| 1556 if (this.readyState == this.DONE) { | 1558 if (this.readyState == this.DONE) { |
| 1557 if (this.status == 200) { | 1559 if (this.status == 200) { |
| 1558 if (this.responseText == '$waitSignal') { | 1560 if (this.responseText == '$waitSignal') { |
| 1559 setTimeout(getNextTask, 500); | 1561 setTimeout(getNextTask, 500); |
| 1560 } else if (this.responseText == '$terminateSignal') { | 1562 } else if (this.responseText == '$terminateSignal') { |
| 1561 // Don't do anything, we will be killed shortly. | 1563 // Don't do anything, we will be killed shortly. |
| 1562 } else { | 1564 } else { |
| 1563 var elapsed = new Date() - start; | 1565 var elapsed = new Date() - start; |
| 1564 var nextTask = JSON.parse(this.responseText); | 1566 var nextTask = JSON.parse(this.responseText); |
| 1565 var url = nextTask.url; | 1567 var url = nextTask.url; |
| 1566 next_id = nextTask.id; | 1568 next_id = nextTask.id; |
| 1567 if (nextTask.isHtmlTest) { | 1569 if (nextTask.isHtmlTest) { |
| 1568 html_test = { | 1570 html_test = { |
| 1569 expected_messages: nextTask.expectedMessages, | 1571 expected_messages: nextTask.expectedMessages, |
| 1570 found_message_count: 0, | 1572 found_message_count: 0, |
| 1571 double_received_messages: [], | 1573 double_received_messages: [], |
| 1572 unexpected_messages: [], | 1574 unexpected_messages: [], |
| 1573 found_messages: {} | 1575 found_messages: {} |
| 1574 }; | 1576 }; |
| 1575 for (var i = 0; i < html_test.expected_messages.length; ++i) { | 1577 for (var i = 0; i < html_test.expected_messages.length; ++i) { |
| 1576 html_test.found_messages[html_test.expected_messages[i]] = 0; | 1578 html_test.found_messages[html_test.expected_messages[i]] = 0; |
| 1577 } | 1579 } |
| 1578 } else { | 1580 } else { |
| 1579 html_test = null; | 1581 html_test = null; |
| 1580 } | 1582 } |
| 1581 run(url); | 1583 run(url); |
| 1582 } | 1584 } |
| 1583 } else { | 1585 } else { |
| 1584 reportError('Could not contact the server and get a new task'); | 1586 reportError('Could not contact the server and get a new task'); |
| 1585 } | 1587 } |
| 1586 } | 1588 } |
| 1587 } | 1589 } |
| 1588 | 1590 |
| 1589 function contactBrowserController(method, | 1591 function contactBrowserController(method, |
| 1590 path, | 1592 path, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1604 function getNextTask() { | 1606 function getNextTask() { |
| 1605 // Until we have the next task we set the current_id to a specific | 1607 // Until we have the next task we set the current_id to a specific |
| 1606 // negative value. | 1608 // negative value. |
| 1607 contactBrowserController( | 1609 contactBrowserController( |
| 1608 'GET', '$nextTestPath/$browserId', newTaskHandler, "", false); | 1610 'GET', '$nextTestPath/$browserId', newTaskHandler, "", false); |
| 1609 } | 1611 } |
| 1610 | 1612 |
| 1611 function childError(message, filename, lineno, colno, error) { | 1613 function childError(message, filename, lineno, colno, error) { |
| 1612 sendStatusUpdate(); | 1614 sendStatusUpdate(); |
| 1613 if (error) { | 1615 if (error) { |
| 1614 reportMessage('FAIL:' + filename + ':' + lineno + | 1616 reportMessage('FAIL:' + filename + ':' + lineno + |
| 1615 ':' + colno + ':' + message + '\\n' + error.stack, false, false); | 1617 ':' + colno + ':' + message + '\\n' + error.stack, false, false); |
| 1616 } else if (filename) { | 1618 } else if (filename) { |
| 1617 reportMessage('FAIL:' + filename + ':' + lineno + | 1619 reportMessage('FAIL:' + filename + ':' + lineno + |
| 1618 ':' + colno + ':' + message, false, false); | 1620 ':' + colno + ':' + message, false, false); |
| 1619 } else { | 1621 } else { |
| 1620 reportMessage('FAIL: ' + message, false, false); | 1622 reportMessage('FAIL: ' + message, false, false); |
| 1621 } | 1623 } |
| 1622 return true; | 1624 return true; |
| 1623 } | 1625 } |
| 1624 | 1626 |
| 1625 function setChildHandlers(e) { | 1627 function setChildHandlers(e) { |
| 1626 embedded_iframe.contentWindow.addEventListener('message', | 1628 embedded_iframe.contentWindow.addEventListener('message', |
| 1627 childMessageHandler, | 1629 childMessageHandler, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 // This handler is installed on the child window when it sends the | 1801 // This handler is installed on the child window when it sends the |
| 1800 // 'detect_errors' event. Every HTML test must send 'detect_errors' to | 1802 // 'detect_errors' event. Every HTML test must send 'detect_errors' to |
| 1801 // its parent window as its first action, so all errors will be caught. | 1803 // its parent window as its first action, so all errors will be caught. |
| 1802 function childMessageHandler(e) { | 1804 function childMessageHandler(e) { |
| 1803 var msg = e.data; | 1805 var msg = e.data; |
| 1804 if (typeof msg != 'string') return; | 1806 if (typeof msg != 'string') return; |
| 1805 if (msg in html_test.found_messages) { | 1807 if (msg in html_test.found_messages) { |
| 1806 html_test.found_messages[msg]++; | 1808 html_test.found_messages[msg]++; |
| 1807 if (html_test.found_messages[msg] == 1) { | 1809 if (html_test.found_messages[msg] == 1) { |
| 1808 html_test.found_message_count++; | 1810 html_test.found_message_count++; |
| 1809 } else { | 1811 } else { |
| 1810 html_test.double_received_messages.push(msg); | 1812 html_test.double_received_messages.push(msg); |
| 1811 sendStatusUpdate(); | 1813 sendStatusUpdate(); |
| 1812 } | 1814 } |
| 1813 } else { | 1815 } else { |
| 1814 html_test.unexpected_messages.push(msg); | 1816 html_test.unexpected_messages.push(msg); |
| 1815 sendStatusUpdate(); | 1817 sendStatusUpdate(); |
| 1816 } | 1818 } |
| 1817 if (html_test.found_message_count == | 1819 if (html_test.found_message_count == |
| 1818 html_test.expected_messages.length) { | 1820 html_test.expected_messages.length) { |
| 1819 reportMessage('Test done: PASS', false, false); | 1821 reportMessage('Test done: PASS', false, false); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1849 </div> | 1851 </div> |
| 1850 <div id="embedded_iframe_div" class="test box"> | 1852 <div id="embedded_iframe_div" class="test box"> |
| 1851 <iframe id="embedded_iframe"></iframe> | 1853 <iframe id="embedded_iframe"></iframe> |
| 1852 </div> | 1854 </div> |
| 1853 </body> | 1855 </body> |
| 1854 </html> | 1856 </html> |
| 1855 """; | 1857 """; |
| 1856 return driverContent; | 1858 return driverContent; |
| 1857 } | 1859 } |
| 1858 } | 1860 } |
| OLD | NEW |