diff options
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/testing/.svn')
128 files changed, 0 insertions, 20948 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/all-wcprops b/contexts/data/lib/closure-library/closure/goog/testing/.svn/all-wcprops deleted file mode 100644 index 2553176..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/all-wcprops +++ /dev/null @@ -1,383 +0,0 @@ -K 25 -svn:wc:ra_dav:version-url -V 45 -/svn/!svn/ver/1472/trunk/closure/goog/testing -END -continuationtestcase.js -K 25 -svn:wc:ra_dav:version-url -V 69 -/svn/!svn/ver/1302/trunk/closure/goog/testing/continuationtestcase.js -END -mockmatchers_test.html -K 25 -svn:wc:ra_dav:version-url -V 67 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockmatchers_test.html -END -mockclassfactory.js -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockclassfactory.js -END -asynctestcase.js -K 25 -svn:wc:ra_dav:version-url -V 62 -/svn/!svn/ver/1302/trunk/closure/goog/testing/asynctestcase.js -END -testcase.js -K 25 -svn:wc:ra_dav:version-url -V 57 -/svn/!svn/ver/1472/trunk/closure/goog/testing/testcase.js -END -recordfunction_test.html -K 25 -svn:wc:ra_dav:version-url -V 70 -/svn/!svn/ver/1165/trunk/closure/goog/testing/recordfunction_test.html -END -jsunit.js -K 25 -svn:wc:ra_dav:version-url -V 54 -/svn/!svn/ver/850/trunk/closure/goog/testing/jsunit.js -END -deferredtestcase.js -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/deferredtestcase.js -END -multitestrunner.js -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/1302/trunk/closure/goog/testing/multitestrunner.js -END -stacktrace.js -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/850/trunk/closure/goog/testing/stacktrace.js -END -functionmock_test.html -K 25 -svn:wc:ra_dav:version-url -V 68 -/svn/!svn/ver/1120/trunk/closure/goog/testing/functionmock_test.html -END -asynctestcase_noasync_test.html -K 25 -svn:wc:ra_dav:version-url -V 76 -/svn/!svn/ver/850/trunk/closure/goog/testing/asynctestcase_noasync_test.html -END -shardingtestcase.js -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/shardingtestcase.js -END -expectedfailures.js -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/expectedfailures.js -END -mockrange_test.html -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockrange_test.html -END -mockuseragent_test.html -K 25 -svn:wc:ra_dav:version-url -V 68 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockuseragent_test.html -END -asynctestcase_test.html -K 25 -svn:wc:ra_dav:version-url -V 69 -/svn/!svn/ver/1259/trunk/closure/goog/testing/asynctestcase_test.html -END -objectpropertystring.js -K 25 -svn:wc:ra_dav:version-url -V 68 -/svn/!svn/ver/850/trunk/closure/goog/testing/objectpropertystring.js -END -mockclock.js -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/1366/trunk/closure/goog/testing/mockclock.js -END -mockrange.js -K 25 -svn:wc:ra_dav:version-url -V 57 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockrange.js -END -testrunner.js -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/850/trunk/closure/goog/testing/testrunner.js -END -loosemock_test.html -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/loosemock_test.html -END -asserts.js -K 25 -svn:wc:ra_dav:version-url -V 56 -/svn/!svn/ver/1472/trunk/closure/goog/testing/asserts.js -END -performancetable.css -K 25 -svn:wc:ra_dav:version-url -V 65 -/svn/!svn/ver/850/trunk/closure/goog/testing/performancetable.css -END -mock.js -K 25 -svn:wc:ra_dav:version-url -V 53 -/svn/!svn/ver/1120/trunk/closure/goog/testing/mock.js -END -propertyreplacer_test.html -K 25 -svn:wc:ra_dav:version-url -V 71 -/svn/!svn/ver/850/trunk/closure/goog/testing/propertyreplacer_test.html -END -performancetimer_test.html -K 25 -svn:wc:ra_dav:version-url -V 72 -/svn/!svn/ver/1472/trunk/closure/goog/testing/performancetimer_test.html -END -singleton_test.html -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/singleton_test.html -END -benchmark.js -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/1270/trunk/closure/goog/testing/benchmark.js -END -mockclock_test.html -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockclock_test.html -END -functionmock.js -K 25 -svn:wc:ra_dav:version-url -V 61 -/svn/!svn/ver/1120/trunk/closure/goog/testing/functionmock.js -END -pseudorandom.js -K 25 -svn:wc:ra_dav:version-url -V 61 -/svn/!svn/ver/1302/trunk/closure/goog/testing/pseudorandom.js -END -propertyreplacer.js -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/testing/propertyreplacer.js -END -performancetimer.js -K 25 -svn:wc:ra_dav:version-url -V 65 -/svn/!svn/ver/1472/trunk/closure/goog/testing/performancetimer.js -END -singleton.js -K 25 -svn:wc:ra_dav:version-url -V 57 -/svn/!svn/ver/850/trunk/closure/goog/testing/singleton.js -END -deferredtestcase_test.html -K 25 -svn:wc:ra_dav:version-url -V 72 -/svn/!svn/ver/1434/trunk/closure/goog/testing/deferredtestcase_test.html -END -dom_test.html -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/850/trunk/closure/goog/testing/dom_test.html -END -mockuseragent.js -K 25 -svn:wc:ra_dav:version-url -V 62 -/svn/!svn/ver/1302/trunk/closure/goog/testing/mockuseragent.js -END -mockinterface.js -K 25 -svn:wc:ra_dav:version-url -V 61 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockinterface.js -END -stacktrace_test.html -K 25 -svn:wc:ra_dav:version-url -V 65 -/svn/!svn/ver/850/trunk/closure/goog/testing/stacktrace_test.html -END -mock_test.html -K 25 -svn:wc:ra_dav:version-url -V 60 -/svn/!svn/ver/1104/trunk/closure/goog/testing/mock_test.html -END -mockmatchers.js -K 25 -svn:wc:ra_dav:version-url -V 61 -/svn/!svn/ver/1302/trunk/closure/goog/testing/mockmatchers.js -END -mockcontrol_test.html -K 25 -svn:wc:ra_dav:version-url -V 66 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockcontrol_test.html -END -expectedfailures_test.html -K 25 -svn:wc:ra_dav:version-url -V 71 -/svn/!svn/ver/850/trunk/closure/goog/testing/expectedfailures_test.html -END -recordfunction.js -K 25 -svn:wc:ra_dav:version-url -V 63 -/svn/!svn/ver/1165/trunk/closure/goog/testing/recordfunction.js -END -mockcontrol.js -K 25 -svn:wc:ra_dav:version-url -V 60 -/svn/!svn/ver/1120/trunk/closure/goog/testing/mockcontrol.js -END -loosemock.js -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/1302/trunk/closure/goog/testing/loosemock.js -END -asynctestcase_async_test.html -K 25 -svn:wc:ra_dav:version-url -V 74 -/svn/!svn/ver/850/trunk/closure/goog/testing/asynctestcase_async_test.html -END -mockclassfactory_test.html -K 25 -svn:wc:ra_dav:version-url -V 71 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockclassfactory_test.html -END -graphics.js -K 25 -svn:wc:ra_dav:version-url -V 56 -/svn/!svn/ver/850/trunk/closure/goog/testing/graphics.js -END -mockstorage_test.html -K 25 -svn:wc:ra_dav:version-url -V 66 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockstorage_test.html -END -performancetable.js -K 25 -svn:wc:ra_dav:version-url -V 65 -/svn/!svn/ver/1472/trunk/closure/goog/testing/performancetable.js -END -strictmock_test.html -K 25 -svn:wc:ra_dav:version-url -V 66 -/svn/!svn/ver/1048/trunk/closure/goog/testing/strictmock_test.html -END -asserts_test.html -K 25 -svn:wc:ra_dav:version-url -V 63 -/svn/!svn/ver/1472/trunk/closure/goog/testing/asserts_test.html -END -mockstorage.js -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockstorage.js -END -dom.js -K 25 -svn:wc:ra_dav:version-url -V 52 -/svn/!svn/ver/1324/trunk/closure/goog/testing/dom.js -END -mockrandom_test.html -K 25 -svn:wc:ra_dav:version-url -V 65 -/svn/!svn/ver/850/trunk/closure/goog/testing/mockrandom_test.html -END -shardingtestcase_test.html -K 25 -svn:wc:ra_dav:version-url -V 71 -/svn/!svn/ver/850/trunk/closure/goog/testing/shardingtestcase_test.html -END -strictmock.js -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/1302/trunk/closure/goog/testing/strictmock.js -END -testqueue.js -K 25 -svn:wc:ra_dav:version-url -V 57 -/svn/!svn/ver/850/trunk/closure/goog/testing/testqueue.js -END -pseudorandom_test.html -K 25 -svn:wc:ra_dav:version-url -V 67 -/svn/!svn/ver/941/trunk/closure/goog/testing/pseudorandom_test.html -END -mockrandom.js -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/1302/trunk/closure/goog/testing/mockrandom.js -END -continuationtestcase_test.html -K 25 -svn:wc:ra_dav:version-url -V 75 -/svn/!svn/ver/850/trunk/closure/goog/testing/continuationtestcase_test.html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/entries b/contexts/data/lib/closure-library/closure/goog/testing/.svn/entries deleted file mode 100644 index cdda153..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/entries +++ /dev/null @@ -1,2197 +0,0 @@ -10 - -dir -1494 -http://closure-library.googlecode.com/svn/trunk/closure/goog/testing -http://closure-library.googlecode.com/svn - - - -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com - - - - - - - - - - - - - - -0b95b8e8-c90f-11de-9d4f-f947ee5921c8 - -continuationtestcase.js -file - - - - -2011-12-23T22:42:27.336316Z -695af05e13ddec06f703a1f2def7a166 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -20544 - -mockmatchers_test.html -file - - - - -2011-12-23T22:42:27.337316Z -a121ff4ce11c0ce263630fe0412d09ea -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -13683 - -mockclassfactory.js -file - - - - -2011-12-23T22:42:27.337316Z -b4e4e72720eaf8514dabf004c98acd58 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -19442 - -asynctestcase.js -file - - - - -2011-12-23T22:42:27.338316Z -610f20380d1a4d77020b5ea7364a2e74 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -24373 - -testcase.js -file - - - - -2011-12-23T22:42:27.339316Z -4b0aa66ab016790f7264544b525e9483 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -29980 - -recordfunction_test.html -file - - - - -2011-12-23T22:42:27.338316Z -b728120b7f6d87d48a797f5f9549acce -2011-07-26T21:39:45.000000Z -1165 -nnaze@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5463 - -deferredtestcase.js -file - - - - -2011-12-23T22:42:27.339316Z -c8e04044b96ee368f702ff40bf2d01a0 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5158 - -jsunit.js -file - - - - -2011-12-23T22:42:27.340316Z -de3a6b5981bdb31c8795d6a8a3add3b9 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5264 - -stacktrace.js -file - - - - -2011-12-23T22:42:27.340316Z -e8b866246cd5d7b625e41d66f487b53a -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -14422 - -multitestrunner.js -file - - - - -2011-12-23T22:42:27.341316Z -6dfcd13d160a852de34a1151e82cd255 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -38154 - -functionmock_test.html -file - - - - -2011-12-23T22:42:27.341316Z -2e70f38a007a016090fbe907daeae995 -2011-07-13T20:04:08.000000Z -1120 -erikwright@google.com -has-props - - - - - - - - - - - - - - - - - - - - -15501 - -events -dir - -asynctestcase_noasync_test.html -file - - - - -2011-12-23T22:42:27.342316Z -6d5dd8c027680d58df2cdd8073a65e63 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2968 - -shardingtestcase.js -file - - - - -2011-12-23T22:42:27.342316Z -8df202c091194f5d83578b2fdccee91a -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4130 - -expectedfailures.js -file - - - - -2011-12-23T22:42:27.343316Z -bd9e17d94d9ca1e9ddb3bccf3f66df93 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -6833 - -fs -dir - -mockrange_test.html -file - - - - -2011-12-23T22:42:27.343316Z -f9547b4f26783c4597360a1e45d60801 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -992 - -mockuseragent_test.html -file - - - - -2011-12-23T22:42:27.343316Z -d67ddf6fa9c384121c358e912099d8c5 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1568 - -asynctestcase_test.html -file - - - - -2011-12-23T22:42:27.344316Z -d8de9bc3f5391d7539e4f1cf540696af -2011-08-29T23:49:09.000000Z -1259 -licong@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1470 - -benchmarks -dir - -objectpropertystring.js -file - - - - -2011-12-23T22:42:27.344316Z -b9d5be35c644d05b795c071da9e8c83f -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1770 - -mockclock.js -file - - - - -2011-12-23T22:42:27.344316Z -9d1f2d2e8d5f83c9f5a1e336ab02ed4b -2011-11-02T22:38:28.000000Z -1366 -ryo@google.com -has-props - - - - - - - - - - - - - - - - - - - - -12535 - -mockrange.js -file - - - - -2011-12-23T22:42:27.344316Z -5103433afc8881b9c26b1ee6feee49e1 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2095 - -testrunner.js -file - - - - -2011-12-23T22:42:27.345316Z -0c490b799e23cc4b001a892eae550ccc -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -11015 - -loosemock_test.html -file - - - - -2011-12-23T22:42:27.345316Z -fa0aab58af5d0f6cd93d5719732ab3ba -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -8125 - -asserts.js -file - - - - -2011-12-23T22:42:27.345316Z -98a339308eb4d11c931ac5d499515d11 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -35298 - -performancetable.css -file - - - - -2011-12-23T22:42:27.345316Z -70e0c8412fd883a6dc05c99b143b1b11 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -928 - -singleton_test.html -file - - - - -2011-12-23T22:42:27.346316Z -3bae89135c52551b5acfce4b9b20444c -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -978 - -performancetimer_test.html -file - - - - -2011-12-23T22:42:27.346316Z -109de253c3b811e30ccb2a717a5aae39 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3200 - -propertyreplacer_test.html -file - - - - -2011-12-23T22:42:27.346316Z -18bb76a4467a69f77ccb72a123ea6f4a -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -11822 - -mock.js -file - - - - -2011-12-23T22:42:27.346316Z -de28aa21358d29e106e4f2b83bdfc482 -2011-07-13T20:04:08.000000Z -1120 -erikwright@google.com -has-props - - - - - - - - - - - - - - - - - - - - -16959 - -benchmark.js -file - - - - -2011-12-23T22:42:27.347316Z -a177e77015d784da524192b4515d137f -2011-09-06T21:26:02.000000Z -1270 -nicksantos@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2593 - -mockclock_test.html -file - - - - -2011-12-23T22:42:27.347316Z -1c175d0a73d8df3f7da200d6f3a320e4 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -11386 - -functionmock.js -file - - - - -2011-12-23T22:42:27.347316Z -423b52f5d8982769946a309aad0ab8f4 -2011-07-13T20:04:08.000000Z -1120 -erikwright@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7203 - -pseudorandom.js -file - - - - -2011-12-23T22:42:27.348316Z -bff64ce11adb599a3c2ef9362e0e381d -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4326 - -propertyreplacer.js -file - - - - -2011-12-23T22:42:27.348316Z -ac37e82d42da27220a130abf48e4d792 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -8409 - -performancetimer.js -file - - - - -2011-12-23T22:42:27.348316Z -388f1fce25867bd0f177d337b7c4ddcd -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5023 - -singleton.js -file - - - - -2011-12-23T22:42:27.348316Z -b468a46251896c6621fa4e91addec088 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2642 - -async -dir - -deferredtestcase_test.html -file - - - - -2011-12-23T22:42:27.349316Z -f3d69712e0941471748baac6e059c23f -2011-11-30T22:16:21.000000Z -1434 -chrishenry@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4719 - -dom_test.html -file - - - - -2011-12-23T22:42:27.349316Z -8d8a735c2a5e0e7fda6122ca5c00f63b -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -15713 - -mockuseragent.js -file - - - - -2011-12-23T22:42:27.349316Z -505e0afbb774a5dfc81ffa0e6f441ffb -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3577 - -mockinterface.js -file - - - - -2011-12-23T22:42:27.349316Z -dd8894fe82bb5a3ea805c6951bb8f5d4 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1318 - -stacktrace_test.html -file - - - - -2011-12-23T22:42:27.350316Z -113cd09b029a87704dd364a9e76f3d47 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -8705 - -mock_test.html -file - - - - -2011-12-23T22:42:27.350316Z -a2b5969a160ea11931c5b1df6bace30f -2011-07-07T03:19:14.000000Z -1104 -erikwright@google.com -has-props - - - - - - - - - - - - - - - - - - - - -6662 - -mockmatchers.js -file - - - - -2011-12-23T22:42:27.350316Z -c5a3f76b252bd743c7896f143f030043 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -13245 - -mockcontrol_test.html -file - - - - -2011-12-23T22:42:27.350316Z -06f58af6ee3e620b76a4231dae378173 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3138 - -expectedfailures_test.html -file - - - - -2011-12-23T22:42:27.351316Z -814d0a7fafb0211961d6fe2e52399352 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3599 - -recordfunction.js -file - - - - -2011-12-23T22:42:27.351316Z -181569e4e3dfff85c9cb369786bf63e6 -2011-07-26T21:39:45.000000Z -1165 -nnaze@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5744 - -mockcontrol.js -file - - - - -2011-12-23T22:42:27.352316Z -c61425cdfc05fcec9a42399c6c4b91b7 -2011-07-13T20:04:08.000000Z -1120 -erikwright@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7311 - -loosemock.js -file - - - - -2011-12-23T22:42:27.352316Z -1855fc25ad62c532df19ff76c9f0a7eb -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -8270 - -asynctestcase_async_test.html -file - - - - -2011-12-23T22:42:27.352316Z -9b3481d18fac97a852572aabf3b8420f -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3038 - -mockclassfactory_test.html -file - - - - -2011-12-23T22:42:27.352316Z -c271e78436f30b0f672031715ecf767d -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -6996 - -graphics.js -file - - - - -2011-12-23T22:42:27.353316Z -93e416fc4ec7fc016f4955a6f1706b13 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2104 - -messaging -dir - -mockstorage_test.html -file - - - - -2011-12-23T22:42:27.353316Z -51dbf94c74aec85b1fd0575455fdf6dd -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2101 - -performancetable.js -file - - - - -2011-12-23T22:42:27.354316Z -9ba35e038ee4fb4c4cffda1855ad0232 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4890 - -strictmock_test.html -file - - - - -2011-12-23T22:42:27.353316Z -a5702a4b77f4ce14d062a1dc2e3108e3 -2011-06-15T23:39:28.000000Z -1048 -nsw@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7546 - -asserts_test.html -file - - - - -2011-12-23T22:42:27.354316Z -a130a6a351f4b599ebb026c6b75ce5e4 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -34256 - -net -dir - -editor -dir - -mockstorage.js -file - - - - -2011-12-23T22:42:27.354316Z -d2158cd7bee1f3181927c16521d0e92b -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2660 - -dom.js -file - - - - -2011-12-23T22:42:27.355316Z -ef55e8d85aaee295507cbe47b76d699c -2011-10-06T21:57:41.000000Z -1324 -brenneman@google.com -has-props - - - - - - - - - - - - - - - - - - - - -21968 - -mockrandom_test.html -file - - - - -2011-12-23T22:42:27.355316Z -6011022f376605b8298f5616881fbfa6 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1396 - -strictmock.js -file - - - - -2011-12-23T22:42:27.355316Z -0362ff2b4889fc933f7366a934c88f29 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4231 - -shardingtestcase_test.html -file - - - - -2011-12-23T22:42:27.355316Z -f7bc9b0b044ce7a41044b0a90597d883 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -735 - -testqueue.js -file - - - - -2011-12-23T22:42:27.356316Z -3194c13a4d56f8deaccb16f1e13ec610 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1715 - -style -dir - -pseudorandom_test.html -file - - - - -2011-12-23T22:42:27.356316Z -d3f76638e3d1f2fad346b48d951af5f5 -2011-05-18T16:54:44.000000Z -941 -azzie@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2594 - -mockrandom.js -file - - - - -2011-12-23T22:42:27.356316Z -ab956e961b72fcd71eea517210f34484 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3208 - -continuationtestcase_test.html -file - - - - -2011-12-23T22:42:27.356316Z -0f718a1c0ff162520f054e8cc643fd3b -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -8847 - -ui -dir - diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asserts.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asserts.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asserts.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asserts_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asserts_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asserts_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_async_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_async_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_async_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_noasync_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_noasync_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_noasync_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/asynctestcase_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/benchmark.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/benchmark.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/benchmark.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/continuationtestcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/continuationtestcase.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/continuationtestcase.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/continuationtestcase_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/continuationtestcase_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/continuationtestcase_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/deferredtestcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/deferredtestcase.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/deferredtestcase.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/deferredtestcase_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/deferredtestcase_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/deferredtestcase_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/dom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/dom.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/dom.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/dom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/dom_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/dom_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/expectedfailures.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/expectedfailures.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/expectedfailures.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/expectedfailures_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/expectedfailures_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/expectedfailures_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/functionmock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/functionmock.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/functionmock.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/functionmock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/functionmock_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/functionmock_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/graphics.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/graphics.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/graphics.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/jsunit.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/jsunit.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/jsunit.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/loosemock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/loosemock.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/loosemock.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/loosemock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/loosemock_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/loosemock_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mock.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mock.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mock_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mock_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclassfactory.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclassfactory.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclassfactory.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclassfactory_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclassfactory_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclassfactory_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclock.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclock.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclock_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockclock_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockcontrol.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockcontrol.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockcontrol.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockcontrol_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockcontrol_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockcontrol_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockinterface.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockinterface.js.svn-base deleted file mode 100644 index 7febff5..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockinterface.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 22 -application/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockmatchers.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockmatchers.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockmatchers.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockmatchers_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockmatchers_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockmatchers_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrandom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrandom.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrandom.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrandom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrandom_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrandom_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrange_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockrange_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockstorage.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockstorage.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockstorage.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockstorage_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockstorage_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockstorage_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockuseragent.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockuseragent.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockuseragent.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockuseragent_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockuseragent_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/mockuseragent_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/multitestrunner.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/multitestrunner.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/multitestrunner.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/objectpropertystring.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/objectpropertystring.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/objectpropertystring.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetable.css.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetable.css.svn-base deleted file mode 100644 index 69cd899..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetable.css.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 8 -text/css -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetable.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetable.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetable.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetimer.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetimer.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetimer.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetimer_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetimer_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/performancetimer_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/propertyreplacer.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/propertyreplacer.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/propertyreplacer.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/propertyreplacer_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/propertyreplacer_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/propertyreplacer_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/pseudorandom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/pseudorandom.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/pseudorandom.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/pseudorandom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/pseudorandom_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/pseudorandom_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/recordfunction.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/recordfunction.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/recordfunction.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/recordfunction_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/recordfunction_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/recordfunction_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/shardingtestcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/shardingtestcase.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/shardingtestcase.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/shardingtestcase_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/shardingtestcase_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/shardingtestcase_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/singleton.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/singleton.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/singleton.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/singleton_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/singleton_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/singleton_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/stacktrace.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/stacktrace.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/stacktrace.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/stacktrace_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/stacktrace_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/stacktrace_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/strictmock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/strictmock.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/strictmock.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/strictmock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/strictmock_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/strictmock_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testcase.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testcase.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testqueue.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testqueue.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testqueue.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testrunner.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testrunner.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/prop-base/testrunner.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asserts.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asserts.js.svn-base deleted file mode 100644 index 66810a1..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asserts.js.svn-base +++ /dev/null @@ -1,1070 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -goog.provide('goog.testing.JsUnitException'); -goog.provide('goog.testing.asserts'); - -goog.require('goog.testing.stacktrace'); - -// TODO(user): Copied from JsUnit with some small modifications, we should -// reimplement the asserters. - - -/** - * @typedef {Array|NodeList|Arguments|{length: number}} - */ -goog.testing.asserts.ArrayLike; - -var DOUBLE_EQUALITY_PREDICATE = function(var1, var2) { - return var1 == var2; -}; -var JSUNIT_UNDEFINED_VALUE; -var TO_STRING_EQUALITY_PREDICATE = function(var1, var2) { - return var1.toString() === var2.toString(); -}; - -var PRIMITIVE_EQUALITY_PREDICATES = { - 'String': DOUBLE_EQUALITY_PREDICATE, - 'Number': DOUBLE_EQUALITY_PREDICATE, - 'Boolean': DOUBLE_EQUALITY_PREDICATE, - 'Date': function(date1, date2) { - return date1.getTime() == date2.getTime(); - }, - 'RegExp': TO_STRING_EQUALITY_PREDICATE, - 'Function': TO_STRING_EQUALITY_PREDICATE -}; - - -function _trueTypeOf(something) { - var result = typeof something; - try { - switch (result) { - case 'string': - break; - case 'boolean': - break; - case 'number': - break; - case 'object': - if (something == null) { - result = 'null'; - break; - } - case 'function': - switch (something.constructor) { - case new String('').constructor: - result = 'String'; - break; - case new Boolean(true).constructor: - result = 'Boolean'; - break; - case new Number(0).constructor: - result = 'Number'; - break; - case new Array().constructor: - result = 'Array'; - break; - case new RegExp().constructor: - result = 'RegExp'; - break; - case new Date().constructor: - result = 'Date'; - break; - case Function: - result = 'Function'; - break; - default: - var m = something.constructor.toString().match( - /function\s*([^( ]+)\(/); - if (m) { - result = m[1]; - } else { - break; - } - } - break; - } - } catch (e) { - - } finally { - result = result.substr(0, 1).toUpperCase() + result.substr(1); - } - return result; -} - -function _displayStringForValue(aVar) { - var result = '<' + aVar + '>'; - if (!(aVar === null || aVar === JSUNIT_UNDEFINED_VALUE)) { - result += ' (' + _trueTypeOf(aVar) + ')'; - } - return result; -} - -function fail(failureMessage) { - goog.testing.asserts.raiseException_('Call to fail()', failureMessage); -} - -function argumentsIncludeComments(expectedNumberOfNonCommentArgs, args) { - return args.length == expectedNumberOfNonCommentArgs + 1; -} - -function commentArg(expectedNumberOfNonCommentArgs, args) { - if (argumentsIncludeComments(expectedNumberOfNonCommentArgs, args)) { - return args[0]; - } - - return null; -} - -function nonCommentArg(desiredNonCommentArgIndex, - expectedNumberOfNonCommentArgs, args) { - return argumentsIncludeComments(expectedNumberOfNonCommentArgs, args) ? - args[desiredNonCommentArgIndex] : - args[desiredNonCommentArgIndex - 1]; -} - -function _validateArguments(expectedNumberOfNonCommentArgs, args) { - var valid = args.length == expectedNumberOfNonCommentArgs || - args.length == expectedNumberOfNonCommentArgs + 1 && - goog.isString(args[0]); - _assert(null, valid, 'Incorrect arguments passed to assert function'); -} - -function _assert(comment, booleanValue, failureMessage) { - if (!booleanValue) { - goog.testing.asserts.raiseException_(comment, failureMessage); - } -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assert(a, opt_b) { - _validateArguments(1, arguments); - var comment = commentArg(1, arguments); - var booleanValue = nonCommentArg(1, 1, arguments); - - _assert(comment, goog.isBoolean(booleanValue), - 'Bad argument to assert(boolean)'); - _assert(comment, booleanValue, 'Call to assert(boolean) with false'); -} - - -/** - * Asserts that the function throws an error. - * - * @param {!(string|Function)} a The assertion comment or the function to call. - * @param {!Function=} opt_b The function to call (if the first argument of - * {@code assertThrows} was the comment). - * @return {*} The error thrown by the function. - * @throws {goog.testing.JsUnitException} If the assertion failed. - */ -function assertThrows(a, opt_b) { - _validateArguments(1, arguments); - var func = nonCommentArg(1, 1, arguments); - var comment = commentArg(1, arguments); - _assert(comment, typeof func == 'function', - 'Argument passed to assertThrows is not a function'); - - try { - func(); - } catch (e) { - if (e && goog.isString(e['stacktrace']) && goog.isString(e['message'])) { - // Remove the stack trace appended to the error message by Opera 10.0 - var startIndex = e['message'].length - e['stacktrace'].length; - if (e['message'].indexOf(e['stacktrace'], startIndex) == startIndex) { - e['message'] = e['message'].substr(0, startIndex - 14); - } - } - return e; - } - goog.testing.asserts.raiseException_(comment, - 'No exception thrown from function passed to assertThrows'); -} - - -/** - * Asserts that the function does not throw an error. - * - * @param {!(string|Function)} a The assertion comment or the function to call. - * @param {!Function=} opt_b The function to call (if the first argument of - * {@code assertNotThrows} was the comment). - * @throws {goog.testing.JsUnitException} If the assertion failed. - */ -function assertNotThrows(a, opt_b) { - _validateArguments(1, arguments); - var comment = commentArg(1, arguments); - var func = nonCommentArg(1, 1, arguments); - _assert(comment, typeof func == 'function', - 'Argument passed to assertNotThrows is not a function'); - - try { - func(); - } catch (e) { - comment = comment ? (comment + '\n') : ''; - comment += 'A non expected exception was thrown from function passed to ' + - 'assertNotThrows'; - // Some browsers don't have a stack trace so at least have the error - // description. - var stackTrace = e['stack'] || e['stacktrace'] || e.toString(); - goog.testing.asserts.raiseException_(comment, stackTrace); - } -} - - -/** - * Asserts that the given callback function results in a JsUnitException when - * called, and that the resulting failure message matches the given expected - * message. - * @param {function() : void} callback Function to be run expected to result - * in a JsUnitException (usually contains a call to an assert). - * @param {string=} opt_expectedMessage Failure message expected to be given - * with the exception. - */ -function assertThrowsJsUnitException(callback, opt_expectedMessage) { - var failed = false; - try { - goog.testing.asserts.callWithoutLogging(callback); - } catch (ex) { - if (!ex.isJsUnitException) { - fail('Expected a JsUnitException'); - } - if (typeof opt_expectedMessage != 'undefined' && - ex.message != opt_expectedMessage) { - fail('Expected message [' + opt_expectedMessage + '] but got [' + - ex.message + ']'); - } - failed = true; - } - if (!failed) { - fail('Expected a failure: ' + opt_expectedMessage); - } -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertTrue(a, opt_b) { - _validateArguments(1, arguments); - var comment = commentArg(1, arguments); - var booleanValue = nonCommentArg(1, 1, arguments); - - _assert(comment, goog.isBoolean(booleanValue), - 'Bad argument to assertTrue(boolean)'); - _assert(comment, booleanValue, 'Call to assertTrue(boolean) with false'); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertFalse(a, opt_b) { - _validateArguments(1, arguments); - var comment = commentArg(1, arguments); - var booleanValue = nonCommentArg(1, 1, arguments); - - _assert(comment, goog.isBoolean(booleanValue), - 'Bad argument to assertFalse(boolean)'); - _assert(comment, !booleanValue, 'Call to assertFalse(boolean) with true'); -} - - -/** - * @param {*} a - * @param {*} b - * @param {*=} opt_c - */ -function assertEquals(a, b, opt_c) { - _validateArguments(2, arguments); - var var1 = nonCommentArg(1, 2, arguments); - var var2 = nonCommentArg(2, 2, arguments); - _assert(commentArg(2, arguments), var1 === var2, - 'Expected ' + _displayStringForValue(var1) + ' but was ' + - _displayStringForValue(var2)); -} - - -/** - * @param {*} a - * @param {*} b - * @param {*=} opt_c - */ -function assertNotEquals(a, b, opt_c) { - _validateArguments(2, arguments); - var var1 = nonCommentArg(1, 2, arguments); - var var2 = nonCommentArg(2, 2, arguments); - _assert(commentArg(2, arguments), var1 !== var2, - 'Expected not to be ' + _displayStringForValue(var2)); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertNull(a, opt_b) { - _validateArguments(1, arguments); - var aVar = nonCommentArg(1, 1, arguments); - _assert(commentArg(1, arguments), aVar === null, - 'Expected ' + _displayStringForValue(null) + ' but was ' + - _displayStringForValue(aVar)); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertNotNull(a, opt_b) { - _validateArguments(1, arguments); - var aVar = nonCommentArg(1, 1, arguments); - _assert(commentArg(1, arguments), aVar !== null, - 'Expected not to be ' + _displayStringForValue(null)); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertUndefined(a, opt_b) { - _validateArguments(1, arguments); - var aVar = nonCommentArg(1, 1, arguments); - _assert(commentArg(1, arguments), aVar === JSUNIT_UNDEFINED_VALUE, - 'Expected ' + _displayStringForValue(JSUNIT_UNDEFINED_VALUE) + - ' but was ' + _displayStringForValue(aVar)); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertNotUndefined(a, opt_b) { - _validateArguments(1, arguments); - var aVar = nonCommentArg(1, 1, arguments); - _assert(commentArg(1, arguments), aVar !== JSUNIT_UNDEFINED_VALUE, - 'Expected not to be ' + _displayStringForValue(JSUNIT_UNDEFINED_VALUE)); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertNotNullNorUndefined(a, opt_b) { - _validateArguments(1, arguments); - assertNotNull.apply(null, arguments); - assertNotUndefined.apply(null, arguments); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertNonEmptyString(a, opt_b) { - _validateArguments(1, arguments); - var aVar = nonCommentArg(1, 1, arguments); - _assert(commentArg(1, arguments), - aVar !== JSUNIT_UNDEFINED_VALUE && aVar !== null && - typeof aVar == 'string' && aVar !== '', - 'Expected non-empty string but was ' + _displayStringForValue(aVar)); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertNaN(a, opt_b) { - _validateArguments(1, arguments); - var aVar = nonCommentArg(1, 1, arguments); - _assert(commentArg(1, arguments), isNaN(aVar), 'Expected NaN'); -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertNotNaN(a, opt_b) { - _validateArguments(1, arguments); - var aVar = nonCommentArg(1, 1, arguments); - _assert(commentArg(1, arguments), !isNaN(aVar), 'Expected not NaN'); -} - - -/** - * Runs a function in an environment where test failures are not logged. This is - * useful for testing test code, where failures can be a normal part of a test. - * @param {function() : void} fn Function to run without logging failures. - */ -goog.testing.asserts.callWithoutLogging = function(fn) { - var testRunner = goog.global['G_testRunner']; - var oldLogTestFailure = testRunner['logTestFailure']; - try { - // Any failures in the callback shouldn't be recorded. - testRunner['logTestFailure'] = undefined; - fn(); - } finally { - testRunner['logTestFailure'] = oldLogTestFailure; - } -}; - - -/** - * Determines if two items of any type match, and formulates an error message - * if not. - * @param {*} expected Expected argument to match. - * @param {*} actual Argument as a result of performing the test. - * @return {?string} Null on success, error message on failure. - */ -goog.testing.asserts.findDifferences = function(expected, actual) { - var failures = []; - var seen1 = []; - var seen2 = []; - - // To avoid infinite recursion when the two parameters are self-referential - // along the same path of properties, keep track of the object pairs already - // seen in this call subtree, and abort when a cycle is detected. - // TODO(gboyer,user): The algorithm still does not terminate in cases - // with exponential recursion, e.g. a binary tree with leaf->root links. - // Investigate ways to solve this without significant performance loss - // for the common case. - function innerAssert(var1, var2, path) { - var depth = seen1.length; - if (depth % 2) { - // Compare with midpoint of seen ("Tortoise and hare" loop detection). - // http://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare - // TODO(gboyer,user): For cases with complex cycles the algorithm - // can take a long time to terminate, look into ways to terminate sooner - // without adding more than constant-time work in non-cycle cases. - var mid = depth >> 1; - // Use === to avoid cases like ['x'] == 'x', which is true. - var match1 = seen1[mid] === var1; - var match2 = seen2[mid] === var2; - if (match1 || match2) { - if (!match1 || !match2) { - // Asymmetric cycles, so the objects have different structure. - failures.push('Asymmetric cycle detected at ' + path); - } - return; - } - } - seen1.push(var1); - seen2.push(var2); - innerAssert_(var1, var2, path); - seen1.pop(); - seen2.pop(); - } - - /** - * @suppress {missingProperties} The map_ property is unknown to the compiler - * unless goog.structs.Map is loaded. - */ - function innerAssert_(var1, var2, path) { - if (var1 === var2) { - return; - } - - var typeOfVar1 = _trueTypeOf(var1); - var typeOfVar2 = _trueTypeOf(var2); - - if (typeOfVar1 == typeOfVar2) { - var isArray = typeOfVar1 == 'Array'; - var equalityPredicate = PRIMITIVE_EQUALITY_PREDICATES[typeOfVar1]; - if (equalityPredicate) { - if (!equalityPredicate(var1, var2)) { - failures.push(path + ' expected ' + _displayStringForValue(var1) + - ' but was ' + _displayStringForValue(var2)); - } - } else if (isArray && var1.length != var2.length) { - failures.push(path + ' expected ' + var1.length + '-element array ' + - 'but got a ' + var2.length + '-element array'); - } else { - var childPath = path + (isArray ? '[%s]' : (path ? '.%s' : '%s')); - - // if an object has an __iterator__ property, we have no way of - // actually inspecting its raw properties, and JS 1.7 doesn't - // overload [] to make it possible for someone to generically - // use what the iterator returns to compare the object-managed - // properties. This gets us into deep poo with things like - // goog.structs.Map, at least on systems that support iteration. - if (!var1['__iterator__']) { - for (var prop in var1) { - if (isArray && goog.testing.asserts.isArrayIndexProp_(prop)) { - // Skip array indices for now. We'll handle them later. - continue; - } - - if (prop in var2) { - innerAssert(var1[prop], var2[prop], - childPath.replace('%s', prop)); - } else { - failures.push('property ' + prop + - ' not present in actual ' + (path || typeOfVar2)); - } - } - // make sure there aren't properties in var2 that are missing - // from var1. if there are, then by definition they don't - // match. - for (var prop in var2) { - if (isArray && goog.testing.asserts.isArrayIndexProp_(prop)) { - // Skip array indices for now. We'll handle them later. - continue; - } - - if (!(prop in var1)) { - failures.push('property ' + prop + - ' not present in expected ' + - (path || typeOfVar1)); - } - } - - // Handle array indices by iterating from 0 to arr.length. - // - // Although all browsers allow holes in arrays, browsers - // are inconsistent in what they consider a hole. For example, - // "[0,undefined,2]" has a hole on IE but not on Firefox. - // - // Because our style guide bans for...in iteration over arrays, - // we assume that most users don't care about holes in arrays, - // and that it is ok to say that a hole is equivalent to a slot - // populated with 'undefined'. - if (isArray) { - for (prop = 0; prop < var1.length; prop++) { - innerAssert(var1[prop], var2[prop], - childPath.replace('%s', String(prop))); - } - } - } else { - // special-case for closure objects that have iterators - if (goog.isFunction(var1.equals)) { - // use the object's own equals function, assuming it accepts an - // object and returns a boolean - if (!var1.equals(var2)) { - failures.push('equals() returned false for ' + - (path || typeOfVar1)); - } - } else if (var1.map_) { - // assume goog.structs.Map or goog.structs.Set, where comparing - // their private map_ field is sufficient - innerAssert(var1.map_, var2.map_, childPath.replace('%s', 'map_')); - } else { - // else die, so user knows we can't do anything - failures.push('unable to check ' + (path || typeOfVar1) + - ' for equality: it has an iterator we do not ' + - 'know how to handle. please add an equals method'); - } - } - } - } else { - failures.push(path + ' expected ' + _displayStringForValue(var1) + - ' but was ' + _displayStringForValue(var2)); - } - } - - innerAssert(expected, actual, ''); - return failures.length == 0 ? null : - 'Expected ' + _displayStringForValue(expected) + ' but was ' + - _displayStringForValue(actual) + '\n ' + failures.join('\n '); -}; - - -/** - * Notes: - * Object equality has some nasty browser quirks, and this implementation is - * not 100% correct. For example, - * - * <code> - * var a = [0, 1, 2]; - * var b = [0, 1, 2]; - * delete a[1]; - * b[1] = undefined; - * assertObjectEquals(a, b); // should fail, but currently passes - * </code> - * - * See asserts_test.html for more interesting edge cases. - * - * The first comparison object provided is the expected value, the second is - * the actual. - * - * @param {*} a Assertion message or comparison object. - * @param {*} b Comparison object. - * @param {*=} opt_c Comparison object, if an assertion message was provided. - */ -function assertObjectEquals(a, b, opt_c) { - _validateArguments(2, arguments); - var v1 = nonCommentArg(1, 2, arguments); - var v2 = nonCommentArg(2, 2, arguments); - var failureMessage = commentArg(2, arguments) ? commentArg(2, arguments) : ''; - var differences = goog.testing.asserts.findDifferences(v1, v2); - - _assert(failureMessage, !differences, differences); -} - - -/** - * Compares two arbitrary objects for non-equalness. - * - * All the same caveats as for assertObjectEquals apply here: - * Undefined values may be confused for missing values, or vice versa. - * - * @param {*} a Assertion message or comparison object. - * @param {*} b Comparison object. - * @param {*=} opt_c Comparison object, if an assertion message was provided. - */ -function assertObjectNotEquals(a, b, opt_c) { - _validateArguments(2, arguments); - var v1 = nonCommentArg(1, 2, arguments); - var v2 = nonCommentArg(2, 2, arguments); - var failureMessage = commentArg(2, arguments) ? commentArg(2, arguments) : ''; - var differences = goog.testing.asserts.findDifferences(v1, v2); - - _assert(failureMessage, differences, 'Objects should not be equal'); -} - - -/** - * @param {*} a - * @param {*} b - * @param {*=} opt_c - */ -function assertArrayEquals(a, b, opt_c) { - _validateArguments(2, arguments); - var v1 = nonCommentArg(1, 2, arguments); - var v2 = nonCommentArg(2, 2, arguments); - var failureMessage = commentArg(2, arguments) ? commentArg(2, arguments) : ''; - - var typeOfVar1 = _trueTypeOf(v1); - _assert(failureMessage, - typeOfVar1 == 'Array', - 'Expected an array for assertArrayEquals but found a ' + typeOfVar1); - - var typeOfVar2 = _trueTypeOf(v2); - _assert(failureMessage, - typeOfVar2 == 'Array', - 'Expected an array for assertArrayEquals but found a ' + typeOfVar2); - - assertObjectEquals.apply(null, arguments); -} - - -/** - * Compares two objects that can be accessed like an array and assert that - * each element is equal. - * @param {string|Object} a Failure message (3 arguments) - * or object #1 (2 arguments). - * @param {Object} b Object #1 (2 arguments) or object #2 (3 arguments). - * @param {Object} c Object #2 (3 arguments). - */ -function assertElementsEquals(a, b, c) { - _validateArguments(2, arguments); - - var v1 = nonCommentArg(1, 2, arguments); - var v2 = nonCommentArg(2, 2, arguments); - var failureMessage = commentArg(2, arguments) ? commentArg(2, arguments) : ''; - - if (!v1) { - assert(failureMessage, !v2); - } else { - assertEquals('length mismatch: ' + failureMessage, v1.length, v2.length); - for (var i = 0; i < v1.length; ++i) { - assertEquals( - 'mismatch at index ' + i + ': ' + failureMessage, v1[i], v2[i]); - } - } -} - - -/** - * Compares two objects that can be accessed like an array and assert that - * each element is roughly equal. - * @param {string|Object} a Failure message (4 arguments) - * or object #1 (3 arguments). - * @param {Object} b Object #1 (4 arguments) or object #2 (3 arguments). - * @param {Object|number} c Object #2 (4 arguments) or tolerance (3 arguments). - * @param {number=} opt_d tolerance (4 arguments). - */ -function assertElementsRoughlyEqual(a, b, c, opt_d) { - _validateArguments(3, arguments); - - var v1 = nonCommentArg(1, 3, arguments); - var v2 = nonCommentArg(2, 3, arguments); - var tolerance = nonCommentArg(3, 3, arguments); - var failureMessage = commentArg(3, arguments) ? commentArg(3, arguments) : ''; - - if (!v1) { - assert(failureMessage, !v2); - } else { - assertEquals('length mismatch: ' + failureMessage, v1.length, v2.length); - for (var i = 0; i < v1.length; ++i) { - assertRoughlyEquals(failureMessage, v1[i], v2[i], tolerance); - } - } -} - - -/** - * Compares two array-like objects without taking their order into account. - * @param {string|goog.testing.asserts.ArrayLike} a Assertion message or the - * expected elements. - * @param {goog.testing.asserts.ArrayLike} b Expected elements or the actual - * elements. - * @param {goog.testing.asserts.ArrayLike=} opt_c Actual elements. - */ -function assertSameElements(a, b, opt_c) { - _validateArguments(2, arguments); - var expected = nonCommentArg(1, 2, arguments); - var actual = nonCommentArg(2, 2, arguments); - var message = commentArg(2, arguments); - - assertTrue('Bad arguments to assertSameElements(opt_message, expected: ' + - 'ArrayLike, actual: ArrayLike)', - goog.isArrayLike(expected) && goog.isArrayLike(actual)); - - // Clones expected and actual and converts them to real arrays. - expected = goog.testing.asserts.toArray_(expected); - actual = goog.testing.asserts.toArray_(actual); - // TODO(user): It would be great to show only the difference - // between the expected and actual elements. - _assert(message, expected.length == actual.length, - 'Expected ' + expected.length + ' elements: [' + expected + '], ' + - 'got ' + actual.length + ' elements: [' + actual + ']'); - - var toFind = goog.testing.asserts.toArray_(expected); - for (var i = 0; i < actual.length; i++) { - var index = goog.testing.asserts.indexOf_(toFind, actual[i]); - _assert(message, index != -1, 'Expected [' + expected + '], got [' + - actual + ']'); - toFind.splice(index, 1); - } -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertEvaluatesToTrue(a, opt_b) { - _validateArguments(1, arguments); - var value = nonCommentArg(1, 1, arguments); - if (!value) { - _assert(commentArg(1, arguments), false, 'Expected to evaluate to true'); - } -} - - -/** - * @param {*} a - * @param {*=} opt_b - */ -function assertEvaluatesToFalse(a, opt_b) { - _validateArguments(1, arguments); - var value = nonCommentArg(1, 1, arguments); - if (value) { - _assert(commentArg(1, arguments), false, 'Expected to evaluate to false'); - } -} - - -/** - * @param {*} a - * @param {*} b - * @param {*=} opt_c - */ -function assertHTMLEquals(a, b, opt_c) { - _validateArguments(2, arguments); - var var1 = nonCommentArg(1, 2, arguments); - var var2 = nonCommentArg(2, 2, arguments); - var var1Standardized = standardizeHTML(var1); - var var2Standardized = standardizeHTML(var2); - - _assert(commentArg(2, arguments), var1Standardized === var2Standardized, - 'Expected ' + _displayStringForValue(var1Standardized) + ' but was ' + - _displayStringForValue(var2Standardized)); -} - - -/** - * Compares two CSS property values to make sure that they represent the same - * things. This will normalize values in the browser. For example, in Firefox, - * this assertion will consider "rgb(0, 0, 255)" and "#0000ff" to be identical - * values for the "color" property. This function won't normalize everything -- - * for example, in most browsers, "blue" will not match "#0000ff". It is - * intended only to compensate for unexpected normalizations performed by - * the browser that should also affect your expected value. - * @param {string} a Assertion message, or the CSS property name. - * @param {string} b CSS property name, or the expected value. - * @param {string} c The expected value, or the actual value. - * @param {string=} opt_d The actual value. - */ -function assertCSSValueEquals(a, b, c, opt_d) { - _validateArguments(3, arguments); - var propertyName = nonCommentArg(1, 3, arguments); - var expectedValue = nonCommentArg(2, 3, arguments); - var actualValue = nonCommentArg(3, 3, arguments); - var expectedValueStandardized = - standardizeCSSValue(propertyName, expectedValue); - var actualValueStandardized = - standardizeCSSValue(propertyName, actualValue); - - _assert(commentArg(3, arguments), - expectedValueStandardized == actualValueStandardized, - 'Expected ' + _displayStringForValue(expectedValueStandardized) + - ' but was ' + _displayStringForValue(actualValueStandardized)); -} - - -/** - * @param {*} a - * @param {*} b - * @param {*=} opt_c - */ -function assertHashEquals(a, b, opt_c) { - _validateArguments(2, arguments); - var var1 = nonCommentArg(1, 2, arguments); - var var2 = nonCommentArg(2, 2, arguments); - var message = commentArg(2, arguments); - for (var key in var1) { - _assert(message, - key in var2, 'Expected hash had key ' + key + ' that was not found'); - _assert(message, var1[key] == var2[key], 'Value for key ' + key + - ' mismatch - expected = ' + var1[key] + ', actual = ' + var2[key]); - } - - for (var key in var2) { - _assert(message, key in var1, 'Actual hash had key ' + key + - ' that was not expected'); - } -} - - -/** - * @param {*} a - * @param {*} b - * @param {*} c - * @param {*=} opt_d - */ -function assertRoughlyEquals(a, b, c, opt_d) { - _validateArguments(3, arguments); - var expected = nonCommentArg(1, 3, arguments); - var actual = nonCommentArg(2, 3, arguments); - var tolerance = nonCommentArg(3, 3, arguments); - _assert(commentArg(3, arguments), Math.abs(expected - actual) <= tolerance, - 'Expected ' + expected + ', but got ' + actual + - ' which was more than ' + tolerance + ' away'); -} - - -/** - * Checks if the given element is the member of the given container. - * @param {*} a Failure message (3 arguments) or the contained element - * (2 arguments). - * @param {*} b The contained element (3 arguments) or the container - * (2 arguments). - * @param {*=} opt_c The container. - */ -function assertContains(a, b, opt_c) { - _validateArguments(2, arguments); - var contained = nonCommentArg(1, 2, arguments); - var container = nonCommentArg(2, 2, arguments); - _assert(commentArg(2, arguments), - goog.testing.asserts.contains_(container, contained), - 'Expected \'' + container + '\' to contain \'' + contained + '\''); -} - - -/** - * Checks if the given element is not the member of the given container. - * @param {*} a Failure message (3 arguments) or the contained element - * (2 arguments). - * @param {*} b The contained element (3 arguments) or the container - * (2 arguments). - * @param {*=} opt_c The container. - */ -function assertNotContains(a, b, opt_c) { - _validateArguments(2, arguments); - var contained = nonCommentArg(1, 2, arguments); - var container = nonCommentArg(2, 2, arguments); - _assert(commentArg(2, arguments), - !goog.testing.asserts.contains_(container, contained), - 'Expected \'' + container + '\' not to contain \'' + contained + '\''); -} - - -/** - * Converts an array like object to array or clones it if it's already array. - * @param {goog.testing.asserts.ArrayLike} arrayLike The collection. - * @return {!Array} Copy of the collection as array. - * @private - */ -goog.testing.asserts.toArray_ = function(arrayLike) { - var ret = []; - for (var i = 0; i < arrayLike.length; i++) { - ret[i] = arrayLike[i]; - } - return ret; -}; - - -/** - * Finds the position of the first occurrence of an element in a container. - * @param {goog.testing.asserts.ArrayLike} container - * The array to find the element in. - * @param {*} contained Element to find. - * @return {number} Index of the first occurrence or -1 if not found. - * @private - */ -goog.testing.asserts.indexOf_ = function(container, contained) { - if (container.indexOf) { - return container.indexOf(contained); - } else { - // IE6/7 do not have indexOf so do a search. - for (var i = 0; i < container.length; i++) { - if (container[i] === contained) { - return i; - } - } - return -1; - } -}; - - -/** - * Tells whether the array contains the given element. - * @param {goog.testing.asserts.ArrayLike} container The array to - * find the element in. - * @param {*} contained Element to find. - * @return {boolean} Whether the element is in the array. - * @private - */ -goog.testing.asserts.contains_ = function(container, contained) { - // TODO(user): Can we check for container.contains as well? - // That would give us support for most goog.structs (though weird results - // with anything else with a contains method, like goog.math.Range). Falling - // back with container.some would catch all iterables, too. - return goog.testing.asserts.indexOf_(container, contained) != -1; -}; - -function standardizeHTML(html) { - var translator = document.createElement('DIV'); - translator.innerHTML = html; - - // Trim whitespace from result (without relying on goog.string) - return translator.innerHTML.replace(/^\s+|\s+$/g, ''); -} - - -/** - * Standardizes a CSS value for a given property by applying it to an element - * and then reading it back. - * @param {string} propertyName CSS property name. - * @param {string} value CSS value. - * @return {string} Normalized CSS value. - */ -function standardizeCSSValue(propertyName, value) { - var styleDeclaration = document.createElement('DIV').style; - styleDeclaration[propertyName] = value; - return styleDeclaration[propertyName]; -} - - -/** - * Raises a JsUnit exception with the given comment. - * @param {string} comment A summary for the exception. - * @param {string=} opt_message A description of the exception. - * @private - */ -goog.testing.asserts.raiseException_ = function(comment, opt_message) { - if (goog.global['CLOSURE_INSPECTOR___'] && - goog.global['CLOSURE_INSPECTOR___']['supportsJSUnit']) { - goog.global['CLOSURE_INSPECTOR___']['jsUnitFailure'](comment, opt_message); - } - - throw new goog.testing.JsUnitException(comment, opt_message); -}; - - -/** - * Helper function for assertObjectEquals. Tells us if a given property - * name is an array index. - * @param {string} prop - * @return {boolean} - * @private - */ -goog.testing.asserts.isArrayIndexProp_ = function(prop) { - return (prop | 0) == prop; -}; - - - -/** - * @param {string} comment A summary for the exception. - * @param {?string=} opt_message A description of the exception. - * @constructor - */ -goog.testing.JsUnitException = function(comment, opt_message) { - this.isJsUnitException = true; - this.message = (comment ? comment : '') + - (comment && opt_message ? '\n' : '') + - (opt_message ? opt_message : ''); - this.stackTrace = goog.testing.stacktrace.get(); - // These fields are for compatibility with jsUnitTestManager. - this.comment = comment || null; - this.jsUnitMessage = opt_message || ''; -}; - - -/** @override */ -goog.testing.JsUnitException.prototype.toString = function() { - // TODO(agrieve): Fix dependency in build rules. For more info see - // http://b/2020085 - return '[JsUnitException]'; -}; - -goog.exportSymbol('fail', fail); -goog.exportSymbol('assert', assert); -goog.exportSymbol('assertThrows', assertThrows); -goog.exportSymbol('assertNotThrows', assertNotThrows); -goog.exportSymbol('assertTrue', assertTrue); -goog.exportSymbol('assertFalse', assertFalse); -goog.exportSymbol('assertEquals', assertEquals); -goog.exportSymbol('assertNotEquals', assertNotEquals); -goog.exportSymbol('assertNull', assertNull); -goog.exportSymbol('assertNotNull', assertNotNull); -goog.exportSymbol('assertUndefined', assertUndefined); -goog.exportSymbol('assertNotUndefined', assertNotUndefined); -goog.exportSymbol('assertNotNullNorUndefined', assertNotNullNorUndefined); -goog.exportSymbol('assertNonEmptyString', assertNonEmptyString); -goog.exportSymbol('assertNaN', assertNaN); -goog.exportSymbol('assertNotNaN', assertNotNaN); -goog.exportSymbol('assertObjectEquals', assertObjectEquals); -goog.exportSymbol('assertObjectNotEquals', assertObjectNotEquals); -goog.exportSymbol('assertArrayEquals', assertArrayEquals); -goog.exportSymbol('assertElementsEquals', assertElementsEquals); -goog.exportSymbol('assertElementsRoughlyEqual', assertElementsRoughlyEqual); -goog.exportSymbol('assertSameElements', assertSameElements); -goog.exportSymbol('assertEvaluatesToTrue', assertEvaluatesToTrue); -goog.exportSymbol('assertEvaluatesToFalse', assertEvaluatesToFalse); -goog.exportSymbol('assertHTMLEquals', assertHTMLEquals); -goog.exportSymbol('assertHashEquals', assertHashEquals); -goog.exportSymbol('assertRoughlyEquals', assertRoughlyEquals); -goog.exportSymbol('assertContains', assertContains); -goog.exportSymbol('assertNotContains', assertNotContains); diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asserts_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asserts_test.html.svn-base deleted file mode 100644 index 8d05659..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asserts_test.html.svn-base +++ /dev/null @@ -1,1011 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.asserts</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.iter.Iterator'); - goog.require('goog.iter.StopIteration'); - goog.require('goog.structs.Map'); - goog.require('goog.structs.Set'); - goog.require('goog.testing.asserts'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> -<script> - - function testAssertTrue() { - assertTrue(true); - assertTrue('Good assertion', true); - assertThrowsJsUnitException( - function() { assertTrue(false); }, - 'Call to assertTrue(boolean) with false'); - assertThrowsJsUnitException( - function() { assertTrue('Should be true', false); }, - 'Should be true\nCall to assertTrue(boolean) with false'); - assertThrowsJsUnitException( - function() { assertTrue(null); }, - 'Bad argument to assertTrue(boolean)'); - assertThrowsJsUnitException( - function() { assertTrue(undefined); }, - 'Bad argument to assertTrue(boolean)'); - } - - function testAssertFalse() { - assertFalse(false); - assertFalse('Good assertion', false); - assertThrowsJsUnitException( - function() { assertFalse(true); }, - 'Call to assertFalse(boolean) with true'); - assertThrowsJsUnitException( - function() { assertFalse('Should be false', true); }, - 'Should be false\nCall to assertFalse(boolean) with true'); - assertThrowsJsUnitException( - function() { assertFalse(null); }, - 'Bad argument to assertFalse(boolean)'); - assertThrowsJsUnitException( - function() { assertFalse(undefined); }, - 'Bad argument to assertFalse(boolean)'); - } - - function testAssertEqualsWithString() { - assertEquals('a', 'a'); - assertEquals('Good assertion', 'a', 'a'); - assertThrowsJsUnitException( - function() { assertEquals('a', 'b'); }, - 'Expected <a> (String) but was <b> (String)'); - assertThrowsJsUnitException( - function() { assertEquals('Bad assertion', 'a', 'b'); }, - 'Bad assertion\nExpected <a> (String) but was <b> (String)'); - } - - function testAssertEqualsWithInteger() { - assertEquals(1, 1); - assertEquals('Good assertion', 1, 1); - assertThrowsJsUnitException( - function() { assertEquals(1, 2); }, - 'Expected <1> (Number) but was <2> (Number)'); - assertThrowsJsUnitException( - function() { assertEquals('Bad assertion', 1, 2); }, - 'Bad assertion\nExpected <1> (Number) but was <2> (Number)'); - } - - function testAssertNotEquals() { - assertNotEquals('a', 'b'); - assertNotEquals('a', 'a', 'b'); - assertThrowsJsUnitException( - function() { assertNotEquals('a', 'a'); }, - 'Expected not to be <a> (String)'); - assertThrowsJsUnitException( - function() { assertNotEquals('a', 'a', 'a'); }, - 'a\nExpected not to be <a> (String)'); - } - - function testAssertNull() { - assertNull(null); - assertNull('Good assertion', null); - assertThrowsJsUnitException( - function() { assertNull(true); }, - 'Expected <null> but was <true> (Boolean)'); - assertThrowsJsUnitException( - function() { assertNull('Should be null', false); }, - 'Should be null\nExpected <null> but was <false> (Boolean)'); - assertThrowsJsUnitException( - function() { assertNull(undefined); }, - 'Expected <null> but was <undefined>'); - assertThrowsJsUnitException( - function() { assertNull(1); }, - 'Expected <null> but was <1> (Number)'); - } - - function testAssertNotNull() { - assertNotNull(true); - assertNotNull('Good assertion', true); - assertNotNull(false); - assertNotNull(undefined); - assertNotNull(1); - assertNotNull('a'); - assertThrowsJsUnitException( - function() { assertNotNull(null); }, - 'Expected not to be <null>'); - assertThrowsJsUnitException( - function() { assertNotNull('Should not be null', null); }, - 'Should not be null\nExpected not to be <null>'); - } - - function testAssertUndefined() { - assertUndefined(undefined); - assertUndefined('Good assertion', undefined); - assertThrowsJsUnitException( - function() { assertUndefined(true); }, - 'Expected <undefined> but was <true> (Boolean)'); - assertThrowsJsUnitException( - function() { assertUndefined('Should be undefined', false); }, - 'Should be undefined\nExpected <undefined> but was <false> (Boolean)'); - assertThrowsJsUnitException( - function() { assertUndefined(null); }, - 'Expected <undefined> but was <null>'); - assertThrowsJsUnitException( - function() { assertUndefined(1); }, - 'Expected <undefined> but was <1> (Number)'); - } - - function testAssertNotUndefined() { - assertNotUndefined(true); - assertNotUndefined('Good assertion', true); - assertNotUndefined(false); - assertNotUndefined(null); - assertNotUndefined(1); - assertNotUndefined('a'); - assertThrowsJsUnitException( - function() { assertNotUndefined(undefined); }, - 'Expected not to be <undefined>'); - assertThrowsJsUnitException( - function() { assertNotUndefined('Should not be undefined', undefined); }, - 'Should not be undefined\nExpected not to be <undefined>'); - } - - function testAssertNotNullNorUndefined() { - assertNotNullNorUndefined(true); - assertNotNullNorUndefined('Good assertion', true); - assertNotNullNorUndefined(false); - assertNotNullNorUndefined(1); - assertNotNullNorUndefined(0); - assertNotNullNorUndefined('a'); - assertThrowsJsUnitException(function() { - assertNotNullNorUndefined(undefined); - }, 'Expected not to be <undefined>'); - assertThrowsJsUnitException(function() { - assertNotNullNorUndefined('Should not be undefined', undefined); - }, 'Should not be undefined\nExpected not to be <undefined>'); - assertThrowsJsUnitException(function() { - assertNotNullNorUndefined(null); - }, 'Expected not to be <null>'); - assertThrowsJsUnitException(function() { - assertNotNullNorUndefined('Should not be null', null); - }, 'Should not be null\nExpected not to be <null>'); - } - - function testAssertNonEmptyString() { - assertNonEmptyString('hello'); - assertNonEmptyString('Good assertion', 'hello'); - assertNonEmptyString('true'); - assertNonEmptyString('false'); - assertNonEmptyString('1'); - assertNonEmptyString('null'); - assertNonEmptyString('undefined'); - assertNonEmptyString('\n'); - assertNonEmptyString(' '); - assertThrowsJsUnitException( - function() { assertNonEmptyString(''); }, - 'Expected non-empty string but was <> (String)'); - assertThrowsJsUnitException( - function() { assertNonEmptyString('Should be non-empty string', ''); }, - 'Should be non-empty string\n' + - 'Expected non-empty string but was <> (String)'); - assertThrowsJsUnitException( - function() { assertNonEmptyString(true); }, - 'Expected non-empty string but was <true> (Boolean)'); - assertThrowsJsUnitException( - function() { assertNonEmptyString(false); }, - 'Expected non-empty string but was <false> (Boolean)'); - assertThrowsJsUnitException( - function() { assertNonEmptyString(1); }, - 'Expected non-empty string but was <1> (Number)'); - assertThrowsJsUnitException( - function() { assertNonEmptyString(null); }, - 'Expected non-empty string but was <null>'); - assertThrowsJsUnitException( - function() { assertNonEmptyString(undefined); }, - 'Expected non-empty string but was <undefined>'); - assertThrowsJsUnitException( - function() { assertNonEmptyString(['hello']); }, - 'Expected non-empty string but was <hello> (Array)'); - // Different browsers return different values/types in the failure message - // so don't bother checking if the message is exactly as expected. - assertThrowsJsUnitException( - function() { assertNonEmptyString(goog.dom.createTextNode('hello')); }); - } - - function testAssertNaN() { - assertNaN(NaN); - assertNaN('Good assertion', NaN); - assertThrowsJsUnitException( - function() { assertNaN(1); }, 'Expected NaN'); - assertThrowsJsUnitException( - function() { assertNaN('Should be NaN', 1); }, - 'Should be NaN\nExpected NaN'); - assertThrowsJsUnitException( - function() { assertNaN(true); }, 'Expected NaN'); - assertThrowsJsUnitException( - function() { assertNaN(false); }, 'Expected NaN'); - assertThrowsJsUnitException( - function() { assertNaN(null); }, 'Expected NaN'); - assertThrowsJsUnitException( - function() { assertNaN(''); }, 'Expected NaN'); - - // TODO(user): These assertions fail. We should decide on the - // semantics of assertNaN - //assertThrowsJsUnitException(function() { assertNaN(undefined); }, - // 'Expected NaN'); - //assertThrowsJsUnitException(function() { assertNaN('a'); }, - // 'Expected NaN'); - } - - function testAssertNotNaN() { - assertNotNaN(1); - assertNotNaN('Good assertion', 1); - assertNotNaN(true); - assertNotNaN(false); - assertNotNaN(''); - assertNotNaN(null); - - // TODO(user): These assertions fail. We should decide on the - // semantics of assertNotNaN - //assertNotNaN(undefined); - //assertNotNaN('a'); - - assertThrowsJsUnitException( - function() { assertNotNaN(Number.NaN); }, - 'Expected not NaN'); - assertThrowsJsUnitException( - function() { assertNotNaN('Should not be NaN', Number.NaN); }, - 'Should not be NaN\nExpected not NaN'); - } - - function testAssertObjectEquals() { - var obj1 = [{'a': 'hello', 'b': 'world'}]; - var obj2 = [{'a': 'hello', 'c': 'dear', 'b' : 'world'}]; - - // Check with obj1 and obj2 as first and second arguments respectively. - assertThrows('Objects should not be equal', function() { - assertObjectEquals(obj1, obj2); - }); - - // Check with obj1 and obj2 as second and first arguments respectively. - assertThrows('Objects should not be equal', function() { - assertObjectEquals(obj2, obj1); - }); - - // Test if equal objects are considered equal. - var obj3 = [{'b': 'world', 'a': 'hello'}]; - assertObjectEquals(obj1, obj3); - assertObjectEquals(obj3, obj1); - - // Test with a case where one of the members has an undefined value. - var obj4 = [{'a': 'hello', 'b': undefined}]; - var obj5 = [{'a': 'hello'}]; - - // Check with obj4 and obj5 as first and second arguments respectively. - assertThrows('Objects should not be equal', function() { - assertObjectEquals(obj4, obj5); - }); - - // Check with obj5 and obj4 as first and second arguments respectively. - assertThrows('Objects should not be equal', function() { - assertObjectEquals(obj5, obj4); - }); - } - - function testAssertObjectNotEquals() { - var obj1 = [{'a': 'hello', 'b': 'world'}]; - var obj2 = [{'a': 'hello', 'c': 'dear', 'b' : 'world'}]; - - // Check with obj1 and obj2 as first and second arguments respectively. - assertObjectNotEquals(obj1, obj2); - - // Check with obj1 and obj2 as second and first arguments respectively. - assertObjectNotEquals(obj2, obj1); - - // Test if equal objects are considered equal. - var obj3 = [{'b': 'world', 'a': 'hello'}]; - var error = assertThrows('Objects should be equal', function() { - assertObjectNotEquals(obj1, obj3); - }); - assertContains('Objects should not be equal', error.message); - error = assertThrows('Objects should be equal', function() { - assertObjectNotEquals(obj3, obj1); - }); - assertContains('Objects should not be equal', error.message); - - // Test with a case where one of the members has an undefined value. - var obj4 = [{'a': 'hello', 'b': undefined}]; - var obj5 = [{'a': 'hello'}]; - - // Check with obj4 and obj5 as first and second arguments respectively. - assertObjectNotEquals(obj4, obj5); - - // Check with obj5 and obj4 as first and second arguments respectively. - assertObjectNotEquals(obj5, obj4); - } - - function testAssertObjectEquals2() { - // NOTE: (0 in [undefined]) is true on FF but false on IE. - // (0 in {'0': undefined}) is true on both. - // grrr. - assertObjectEquals('arrays should be equal', [undefined], [undefined]); - assertThrows('arrays should not be equal', function() { - assertObjectEquals([undefined, undefined], [undefined]); - }); - assertThrows('arrays should not be equal', function() { - assertObjectEquals([undefined], [undefined, undefined]); - }); - } - - function testAssertObjectEquals3() { - // Check that objects that contain identical Map objects compare - // as equals. We can't do a negative test because on browsers that - // implement __iterator__ we can't check the values of the iterated - // properties. - var obj1 = [{'a': 'hi', - 'b': new goog.structs.Map('hola', 'amigo', - 'como', 'estas?')}, - 14, - 'yes', - true]; - var obj2 = [{'a': 'hi', - 'b': new goog.structs.Map('hola', 'amigo', - 'como', 'estas?')}, - 14, - 'yes', - true]; - assertObjectEquals('Objects should be equal', obj1, obj2); - - var obj3 = {'a': [1, 2]}; - var obj4 = {'a': [1, 2, 3]}; - assertThrows('inner arrays should not be equal', function() { - assertObjectEquals(obj3, obj4); - }); - assertThrows('inner arrays should not be equal', function() { - assertObjectEquals(obj4, obj3); - }); - } - - function testAssertObjectEqualsSet() { - // verify that Sets compare equal, when run in an environment that - // supports iterators - var set1 = new goog.structs.Set(); - var set2 = new goog.structs.Set(); - - set1.add('a'); - set1.add('b'); - set1.add(13); - - set2.add('a'); - set2.add('b'); - set2.add(13); - - assertObjectEquals('sets should be equal', set1, set2); - - set2.add('hey'); - assertThrows('sets should not be equal', function() { - assertObjectEquals(set1, set2); - }); - } - - function testAssertObjectEqualsIterNoEquals() { - // an object with an iterator but no equals() and no map_ cannot - // be compared - function Thing() { - this.what = []; - } - Thing.prototype.add = function(n, v) { - this.what.push(n + '@' + v); - }; - Thing.prototype.get = function(n) { - var m = new RegExp('^' + n + '@(.*)$', ''); - for (var i = 0; i < this.what.length; ++i) { - var match = this.what[i].match(m); - if (match) { - return match[1]; - } - } - return null; - }; - Thing.prototype.__iterator__ = function() { - var iter = new goog.iter.Iterator; - iter.index = 0; - iter.thing = this; - iter.next = function() { - if (this.index < this.thing.what.length) { - return this.thing.what[this.index++].split('@')[0]; - } else { - throw goog.iter.StopIteration; - } - }; - return iter; - }; - - var thing1 = new Thing(); thing1.name = 'thing1'; - var thing2 = new Thing(); thing2.name = 'thing2'; - thing1.add('red', 'fish'); - thing1.add('blue', 'fish'); - - thing2.add('red', 'fish'); - thing2.add('blue', 'fish'); - - assertThrows('things should not be equal', function() { - assertObjectEquals(thing1, thing2); - }); - } - - function testAssertObjectEqualsWithDates() { - var date = new Date(2010, 0, 1); - var dateWithMilliseconds = new Date(2010, 0, 1, 0, 0, 0, 1); - assertObjectEquals(new Date(2010, 0, 1), date); - assertThrows(goog.partial(assertObjectEquals, date, dateWithMilliseconds)); - } - - function testAssertObjectEqualsSparseArrays() { - var arr1 = [,2,,4,,]; - var arr2 = [1,2,3,4,5]; - - assertThrows('Sparse arrays should not be equal', function() { - assertObjectEquals(arr1, arr2); - }); - - assertThrows('Sparse arrays should not be equal', function() { - assertObjectEquals(arr2, arr1); - }); - } - - function testAssertObjectEqualsSparseArrays2() { - // On IE6-8, the expression "1 in [4,undefined]" evaluates to false, - // but true on other browsers. FML. This test verifies a regression - // where IE reported that arr4 was not equal to arr1 or arr2. - var arr1 = [1,,3]; - var arr2 = [1,undefined,3]; - var arr3 = goog.array.clone(arr1); - var arr4 = []; - arr4.push(1, undefined, 3); - - // Assert that all those arrays are equivalent pairwise. - var arrays = [arr1, arr2, arr3, arr4]; - for (var i = 0; i < arrays.length; i++) { - for (var j = 0; j < arrays.length; j++) { - assertArrayEquals(arrays[i], arrays[j]); - } - } - } - - function testAssertObjectEqualsArraysWithExtraProps() { - var arr1 = [1]; - var arr2 = [1]; - arr2.foo = 3; - - assertThrows('Aarrays should not be equal', function() { - assertObjectEquals(arr1, arr2); - }); - - assertThrows('Arrays should not be equal', function() { - assertObjectEquals(arr2, arr1); - }); - } - - function testAssertSameElementsOnArray() { - assertSameElements([1, 2], [2, 1]); - assertSameElements('Good assertion', [1, 2], [2, 1]); - assertSameElements('Good assertion with duplicates', [1, 1, 2], [2, 1, 1]); - assertThrowsJsUnitException( - function() { - assertSameElements([1, 2], [1]); - }, - 'Expected 2 elements: [1,2], got 1 elements: [1]'); - assertThrowsJsUnitException( - function() { - assertSameElements('Should match', [1, 2], [1]); - }, - 'Should match\nExpected 2 elements: [1,2], got 1 elements: [1]'); - assertThrowsJsUnitException( - function() { - assertSameElements([1, 2], [1, 3]); - }, - 'Expected [1,2], got [1,3]'); - assertThrowsJsUnitException( - function() { - assertSameElements('Should match', [1, 2], [1, 3]); - }, - 'Should match\nExpected [1,2], got [1,3]'); - assertThrowsJsUnitException( - function() { - assertSameElements([1, 1, 2], [2, 2, 1]); - }, - 'Expected [1,1,2], got [2,2,1]'); - } - - function testAssertSameElementsOnArrayLike() { - assertSameElements({0: 0, 1: 1, length: 2}, {length: 2, 1: 1, 0: 0}); - assertThrowsJsUnitException( - function() { - assertSameElements({0: 0, 1: 1, length: 2}, {0: 0, length: 1}); - }, - 'Expected 2 elements: [0,1], got 1 elements: [0]'); - } - - function testAssertSameElementsWithBadArguments() { - assertThrowsJsUnitException( - function() { - assertSameElements([], new goog.structs.Set()); - }, - 'Bad arguments to assertSameElements(opt_message, expected: ' + - 'ArrayLike, actual: ArrayLike)\n' + - 'Call to assertTrue(boolean) with false'); - } - - var implicitlyTrue = [ - true, - 1, - -1, - ' ', - 'string', - Infinity, - new Object() - ]; - - var implicitlyFalse = [ - false, - 0, - '', - null, - undefined, - NaN - ]; - - function testAssertEvaluatesToTrue() { - assertEvaluatesToTrue(true); - assertEvaluatesToTrue('', true); - assertEvaluatesToTrue('Good assertion', true); - assertThrowsJsUnitException( - function() { assertEvaluatesToTrue(false); }, - 'Expected to evaluate to true'); - assertThrowsJsUnitException( - function() {assertEvaluatesToTrue('Should be true', false); }, - 'Should be true\nExpected to evaluate to true'); - for (var i = 0; i < implicitlyTrue.length; i++) { - assertEvaluatesToTrue(String('Test ' + implicitlyTrue[i] + - ' [' + i + ']'), implicitlyTrue[i]); - } - for (var i = 0; i < implicitlyFalse.length; i++) { - assertThrowsJsUnitException( - function() { assertEvaluatesToTrue(implicitlyFalse[i]); }, - 'Expected to evaluate to true'); - } - } - - function testAssertEvaluatesToFalse() { - assertEvaluatesToFalse(false); - assertEvaluatesToFalse('Good assertion', false); - assertThrowsJsUnitException( - function() { assertEvaluatesToFalse(true); }, - 'Expected to evaluate to false'); - assertThrowsJsUnitException( - function() { assertEvaluatesToFalse('Should be false', true); }, - 'Should be false\nExpected to evaluate to false'); - for (var i = 0; i < implicitlyFalse.length; i++) { - assertEvaluatesToFalse(String('Test ' + implicitlyFalse[i] + - ' [' + i + ']'), implicitlyFalse[i]); - } - for (var i = 0; i < implicitlyTrue.length; i++) { - assertThrowsJsUnitException( - function() { assertEvaluatesToFalse(implicitlyTrue[i]); }, - 'Expected to evaluate to false'); - } - } - - function testAssertHTMLEquals() { - // TODO - } - - function testAssertHashEquals() { - assertHashEquals({a: 1, b: 2}, {b: 2, a: 1}); - assertHashEquals('Good assertion', {a: 1, b: 2}, {b: 2, a: 1}); - assertHashEquals({a: undefined}, {a: undefined}); - // Missing key. - assertThrowsJsUnitException( - function() { assertHashEquals({a: 1, b: 2}, {a: 1}); }, - 'Expected hash had key b that was not found'); - assertThrowsJsUnitException( - function() { assertHashEquals('Should match', {a: 1, b: 2}, {a: 1}); }, - 'Should match\nExpected hash had key b that was not found'); - assertThrowsJsUnitException( - function() { assertHashEquals({a: undefined}, {}); }, - 'Expected hash had key a that was not found'); - // Not equal key. - assertThrowsJsUnitException( - function() { assertHashEquals({a: 1}, {a: 5}); }, - 'Value for key a mismatch - expected = 1, actual = 5'); - assertThrowsJsUnitException( - function() { assertHashEquals('Should match', {a: 1}, {a: 5}); }, - 'Should match\nValue for key a mismatch - expected = 1, actual = 5'); - assertThrowsJsUnitException( - function() { assertHashEquals({a: undefined}, {a: 1})}, - 'Value for key a mismatch - expected = undefined, actual = 1'); - // Extra key. - assertThrowsJsUnitException( - function() { assertHashEquals({a: 1}, {a: 1, b: 1}); }, - 'Actual hash had key b that was not expected'); - assertThrowsJsUnitException( - function() { assertHashEquals('Should match', {a: 1}, {a: 1, b: 1}); }, - 'Should match\nActual hash had key b that was not expected'); - } - - function testAssertRoughlyEquals() { - assertRoughlyEquals(1, 1, 0); - assertRoughlyEquals('Good assertion', 1, 1, 0); - assertRoughlyEquals(1, 1.1, 0.11); - assertRoughlyEquals(1.1, 1, 0.11); - assertThrowsJsUnitException( - function() { assertRoughlyEquals(1, 1.1, 0.05); }, - 'Expected 1, but got 1.1 which was more than 0.05 away'); - assertThrowsJsUnitException( - function() { assertRoughlyEquals('Close enough', 1, 1.1, 0.05); }, - 'Close enough\nExpected 1, but got 1.1 which was more than 0.05 away'); - } - - function testAssertContains() { - var a = [1, 2, 3]; - assertContains(1, [1, 2, 3]); - assertContains('Should contain', 1, [1, 2, 3]); - assertThrowsJsUnitException( - function() { assertContains(4, [1, 2, 3]); }, - 'Expected \'1,2,3\' to contain \'4\''); - assertThrowsJsUnitException( - function() { assertContains('Should contain', 4, [1, 2, 3]); }, - 'Should contain\nExpected \'1,2,3\' to contain \'4\''); - // assertContains uses ===. - var o = new Object(); - assertContains(o, [o, 2, 3]); - assertThrowsJsUnitException( - function() { assertContains(o, [1, 2, 3]); }, - 'Expected \'1,2,3\' to contain \'[object Object]\''); - } - - function testAssertNotContains() { - var a = [1, 2, 3]; - assertNotContains(4, [1, 2, 3]); - assertNotContains('Should not contain', 4, [1, 2, 3]); - assertThrowsJsUnitException( - function() { assertNotContains(1, [1, 2, 3]); }, - 'Expected \'1,2,3\' not to contain \'1\''); - assertThrowsJsUnitException( - function() { assertNotContains('Should not contain', 1, [1, 2, 3]); }, - "Should not contain\nExpected '1,2,3' not to contain '1'"); - // assertNotContains uses ===. - var o = new Object(); - assertNotContains({}, [o, 2, 3]); - assertThrowsJsUnitException( - function() { assertNotContains(o, [o, 2, 3]); }, - 'Expected \'[object Object],2,3\' not to contain \'[object Object]\''); - } - - function testAssertThrows() { - var failed = false; - try { - assertThrows('assertThrows should not pass with null param', null); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - try { - assertThrows( - 'assertThrows should not pass with undefined param', - undefined); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - try { - assertThrows('assertThrows should not pass with number param', 1); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - try { - assertThrows('assertThrows should not pass with string param', 'string'); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - try { - assertThrows('assertThrows should not pass with object param', {}); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - try { - var error = assertThrows('valid function throws Error', function() { - throw new Error('test'); - }); - } catch (e) { - fail('assertThrows incorrectly doesn\'t detect a thrown exception'); - } - assertEquals('error message', 'test', error.message); - - try { - var stringError = assertThrows('valid function throws string error', - function() { - throw 'string error test'; - }); - } catch (e) { - fail('assertThrows doesn\'t detect a thrown string exception'); - } - assertEquals('string error', 'string error test', stringError); - } - - function testAssertNotThrows() { - var failed = false; - try { - assertNotThrows('assertNotThrows should not pass with null param', null); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - try { - assertNotThrows( - 'assertNotThrows should not pass with undefined param', undefined); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - try { - assertNotThrows('assertNotThrows should not pass with number param', 1); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - try { - assertNotThrows('assertNotThrows should not pass with string param', - 'string'); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - - try { - assertNotThrows('assertNotThrows should not pass with object param', {}); - failed = true; - } catch (e) { - } - assertFalse('Fail should not get set to true', failed); - - - try { - assertNotThrows('valid function', - function() { - //do nothing; - }); - } catch (e) { - // Shouldn't be here: throw exception. - fail('assertNotThrows returned failure on a valid function'); - } - - var errorDescription = 'a test error exception'; - try { - throw new Error(errorDescription); - assertNotThrows('non valid error throwing function', - function() { - throw new Error(errorDescription); - }); - failed = true; - } catch (e) { - // Some browsers don't have a stack trace so expect to at least have the - // error description. - assertContains(errorDescription, e.message); - } - assertFalse('assertNotThrows did not fail on a thrown exception', failed); - } - - function testAssertArrayEquals() { - var a1 = [0, 1, 2]; - var a2 = [0, 1, 2]; - assertArrayEquals('Arrays should be equal', a1, a2); - - assertThrows('Should have thrown because args are not arrays', function() { - var b1 = true; - var b2 = true; - assertArrayEquals(b1, b2); - }); - } - - function testAssertObjectsEqualsDifferentArrays() { - assertThrows('Should have thrown because args are different', function() { - var a1 = ['className1']; - var a2 = ['className2']; - assertArrayEquals(a1, a2); - assertObjectEquals(a1, a2); - }); - } - - function testAssertObjectsEqualsDifferentTypeSameToString() { - assertThrows('Should have thrown because args are different', function() { - var a1 = 'className1'; - var a2 = ['className1']; - assertObjectEquals(a1, a2); - }); - - assertThrows('Should have thrown because args are different', function() { - var a1 = ['className1']; - var a2 = {'0': 'className1'}; - assertObjectEquals(a1, a2); - }); - - assertThrows('Should have thrown because args are different', function() { - var a1 = ['className1']; - var a2 = [['className1']]; - assertObjectEquals(a1, a2); - }); - } - - function testFindDifferences_equal() { - assertNull(goog.testing.asserts.findDifferences(true, true)); - assertNull(goog.testing.asserts.findDifferences(null, null)); - assertNull(goog.testing.asserts.findDifferences(undefined, undefined)); - assertNull(goog.testing.asserts.findDifferences(1, 1)); - assertNull(goog.testing.asserts.findDifferences([1, 'a'], [1, 'a'])); - assertNull(goog.testing.asserts.findDifferences( - [[1, 2], [3, 4]], [[1, 2], [3, 4]])); - assertNull(goog.testing.asserts.findDifferences( - [{a: 1, b: 2}], [{b: 2, a: 1}])); - assertNull(goog.testing.asserts.findDifferences(null, null)); - assertNull(goog.testing.asserts.findDifferences(undefined, undefined)); - } - - function testFindDifferences_unequal() { - assertNotNull(goog.testing.asserts.findDifferences(true, false)); - assertNotNull(goog.testing.asserts.findDifferences( - [{a: 1, b: 2}], [{a: 2, b: 1}])); - assertNotNull(goog.testing.asserts.findDifferences( - [{a: 1}], [{a: 1, b: [2]}])); - assertNotNull(goog.testing.asserts.findDifferences( - [{a: 1, b: [2]}], [{a: 1}])); - } - - function testFindDifferences_objectsAndNull() { - assertNotNull(goog.testing.asserts.findDifferences({a: 1}, null)); - assertNotNull(goog.testing.asserts.findDifferences(null, {a: 1})); - assertNotNull(goog.testing.asserts.findDifferences(null, [])); - assertNotNull(goog.testing.asserts.findDifferences([], null)); - assertNotNull(goog.testing.asserts.findDifferences([], undefined)); - } - - function testFindDifferences_basicCycle() { - var a = {}; - var b = {}; - a.self = a; - b.self = b; - assertNull(goog.testing.asserts.findDifferences(a, b)); - - a.unique = 1; - assertNotNull(goog.testing.asserts.findDifferences(a, b)); - } - - function testFindDifferences_crossedCycle() { - var a = {}; - var b = {}; - a.self = b; - b.self = a; - assertNull(goog.testing.asserts.findDifferences(a, b)); - - a.unique = 1; - assertNotNull(goog.testing.asserts.findDifferences(a, b)); - } - - function testFindDifferences_asymmetricCycle() { - var a = {}; - var b = {}; - var c = {}; - var d = {}; - var e = {}; - a.self = b; - b.self = a; - c.self = d; - d.self = e; - e.self = c; - assertNotNull(goog.testing.asserts.findDifferences(a, c)); - } - - function testFindDifferences_basicCycleArray() { - var a = []; - var b = []; - a[0] = a; - b[0] = b; - assertNull(goog.testing.asserts.findDifferences(a, b)); - - a[1] = 1; - assertNotNull(goog.testing.asserts.findDifferences(a, b)); - } - - function testFindDifferences_crossedCycleArray() { - var a = []; - var b = []; - a[0] = b; - b[0] = a; - assertNull(goog.testing.asserts.findDifferences(a, b)); - - a[1] = 1; - assertNotNull(goog.testing.asserts.findDifferences(a, b)); - } - - function testFindDifferences_asymmetricCycleArray() { - var a = []; - var b = []; - var c = []; - var d = []; - var e = []; - a[0] = b; - b[0] = a; - c[0] = d; - d[0] = e; - e[0] = c; - assertNotNull(goog.testing.asserts.findDifferences(a, c)); - } - - function testFindDifferences_binaryTree() { - function createBinTree(depth, root) { - if (depth == 0) { - return {root: root}; - } else { - var node = {}; - node.left = createBinTree(depth-1, root || node); - node.right = createBinTree(depth-1, root || node); - return node; - } - } - - // TODO(gboyer,user): This test does not terminate with the current - // algorithm. Can be enabled when (if) the algorithm is improved. - //assertNull(goog.testing.asserts.findDifferences( - // createBinTree(5, null), createBinTree(5, null))); - assertNotNull(goog.testing.asserts.findDifferences( - createBinTree(4, null), createBinTree(5, null))); - } - - function testStringForWindowIE() { - if (goog.userAgent.IE && !goog.userAgent.isVersion('8')) { - // NOTE(user): This test sees of we are being affected by a JScript bug - // in try/finally handling. This bug only affects the lowest try/finally - // block in the stack. Calling this function via VBScript allows - // us to run the test synchronously in an empty JS stack. - window.execScript('stringForWindowIEHelper()', 'vbscript'); - assertEquals('<[object]> (Object)', window.stringForWindowIEResult); - } - } - - function testAssertElementsEquals() { - assertElementsEquals([1, 2], [1, 2]); - assertElementsEquals([1, 2], {0: 1, 1: 2, length: 2}); - assertElementsEquals('Good assertion', [1, 2], [1, 2]); - assertThrowsJsUnitException( - function() { - assertElementsEquals('Message', [1, 2], [1]); - }, - 'length mismatch: Message\n' + - 'Expected <2> (Number) but was <1> (Number)'); - } - - function stringForWindowIEHelper() { - window.stringForWindowIEResult = _displayStringForValue(window); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase.js.svn-base deleted file mode 100644 index 3c4cfd9..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase.js.svn-base +++ /dev/null @@ -1,820 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// All Rights Reserved. - -/** - * @fileoverview A class representing a set of test functions that use - * asynchronous functions that cannot be meaningfully mocked. - * - * To create a Google-compatable JsUnit test using this test case, put the - * following snippet in your test: - * - * var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall(); - * - * To make the test runner wait for your asynchronous behaviour, use: - * - * asyncTestCase.waitForAsync('Waiting for xhr to respond'); - * - * The next test will not start until the following call is made, or a - * timeout occurs: - * - * asyncTestCase.continueTesting(); - * - * There does NOT need to be a 1:1 mapping of waitForAsync calls and - * continueTesting calls. The next test will be run after a single call to - * continueTesting is made, as long as there is no subsequent call to - * waitForAsync in the same thread. - * - * Example: - * // Returning here would cause the next test to be run. - * asyncTestCase.waitForAsync('description 1'); - * // Returning here would *not* cause the next test to be run. - * // Only effect of additional waitForAsync() calls is an updated - * // description in the case of a timeout. - * asyncTestCase.waitForAsync('updated description'); - * asyncTestCase.continueTesting(); - * // Returning here would cause the next test to be run. - * asyncTestCase.waitForAsync('just kidding, still running.'); - * // Returning here would *not* cause the next test to be run. - * - * This class supports asynchronous behaviour in all test functions except for - * tearDownPage. If such support is needed, it can be added. - * - * Example Usage: - * - * var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall(); - * // Optionally, set a longer-than-normal step timeout. - * asyncTestCase.stepTimeout = 30 * 1000; - * - * function testSetTimeout() { - * var step = 0; - * function stepCallback() { - * step++; - * switch (step) { - * case 1: - * var startTime = goog.now(); - * asyncTestCase.waitForAsync('step 1'); - * window.setTimeout(stepCallback, 100); - * break; - * case 2: - * assertTrue('Timeout fired too soon', - * goog.now() - startTime >= 100); - * asyncTestCase.waitForAsync('step 2'); - * window.setTimeout(stepCallback, 100); - * break; - * case 3: - * assertTrue('Timeout fired too soon', - * goog.now() - startTime >= 200); - * asyncTestCase.continueTesting(); - * break; - * default: - * fail('Unexpected call to stepCallback'); - * } - * } - * stepCallback(); - * } - * - * Known Issues: - * IE7 Exceptions: - * As the failingtest.html will show, it appears as though ie7 does not - * propagate an exception past a function called using the func.call() - * syntax. This causes case 3 of the failing tests (exceptions) to show up - * as timeouts in IE. - * window.onerror: - * This seems to catch errors only in ff2/ff3. It does not work in Safari or - * IE7. The consequence of this is that exceptions that would have been - * caught by window.onerror show up as timeouts. - * - * @author agrieve@google.com (Andrew Grieve) - */ - -goog.provide('goog.testing.AsyncTestCase'); -goog.provide('goog.testing.AsyncTestCase.ControlBreakingException'); - -goog.require('goog.testing.TestCase'); -goog.require('goog.testing.TestCase.Test'); -goog.require('goog.testing.asserts'); - - - -/** - * A test case that is capable of running tests the contain asynchronous logic. - * @param {string=} opt_name A descriptive name for the test case. - * @extends {goog.testing.TestCase} - * @constructor - */ -goog.testing.AsyncTestCase = function(opt_name) { - goog.testing.TestCase.call(this, opt_name); -}; -goog.inherits(goog.testing.AsyncTestCase, goog.testing.TestCase); - - -/** - * Represents result of top stack function call. - * @typedef {{controlBreakingExceptionThrown: boolean, message: string}} - * @private - */ -goog.testing.AsyncTestCase.TopStackFuncResult_; - - - -/** - * An exception class used solely for control flow. - * @param {string=} opt_message Error message. - * @constructor - */ -goog.testing.AsyncTestCase.ControlBreakingException = function(opt_message) { - /** - * The exception message. - * @type {string} - */ - this.message = opt_message || ''; -}; - - -/** - * Return value for .toString(). - * @type {string} - */ -goog.testing.AsyncTestCase.ControlBreakingException.TO_STRING = - '[AsyncTestCase.ControlBreakingException]'; - - -/** - * Marks this object as a ControlBreakingException - * @type {boolean} - */ -goog.testing.AsyncTestCase.ControlBreakingException.prototype. - isControlBreakingException = true; - - -/** @override */ -goog.testing.AsyncTestCase.ControlBreakingException.prototype.toString = - function() { - // This shows up in the console when the exception is not caught. - return goog.testing.AsyncTestCase.ControlBreakingException.TO_STRING; -}; - - -/** - * How long to wait for a single step of a test to complete in milliseconds. - * A step starts when a call to waitForAsync() is made. - * @type {number} - */ -goog.testing.AsyncTestCase.prototype.stepTimeout = 1000; - - -/** - * How long to wait after a failed test before moving onto the next one. - * The purpose of this is to allow any pending async callbacks from the failing - * test to finish up and not cause the next test to fail. - * @type {number} - */ -goog.testing.AsyncTestCase.prototype.timeToSleepAfterFailure = 500; - - -/** - * Turn on extra logging to help debug failing async. tests. - * @type {boolean} - * @private - */ -goog.testing.AsyncTestCase.prototype.enableDebugLogs_ = false; - - -/** - * A reference to the original asserts.js assert_() function. - * @private - */ -goog.testing.AsyncTestCase.prototype.origAssert_; - - -/** - * A reference to the original asserts.js fail() function. - * @private - */ -goog.testing.AsyncTestCase.prototype.origFail_; - - -/** - * A reference to the original window.onerror function. - * @type {Function|undefined} - * @private - */ -goog.testing.AsyncTestCase.prototype.origOnError_; - - -/** - * The stage of the test we are currently on. - * @type {Function|undefined}} - * @private - */ -goog.testing.AsyncTestCase.prototype.curStepFunc_; - - -/** - * The name of the stage of the test we are currently on. - * @type {string} - * @private - */ -goog.testing.AsyncTestCase.prototype.curStepName_ = ''; - - -/** - * The stage of the test we should run next. - * @type {Function|undefined} - * @private - */ -goog.testing.AsyncTestCase.prototype.nextStepFunc; - - -/** - * The name of the stage of the test we should run next. - * @type {string} - * @private - */ -goog.testing.AsyncTestCase.prototype.nextStepName_ = ''; - - -/** - * The handle to the current setTimeout timer. - * @type {number|undefined} - * @private - */ -goog.testing.AsyncTestCase.prototype.timeoutHandle_; - - -/** - * Marks if the cleanUp() function has been called for the currently running - * test. - * @type {boolean} - * @private - */ -goog.testing.AsyncTestCase.prototype.cleanedUp_ = false; - - -/** - * The currently active test. - * @type {goog.testing.TestCase.Test|undefined} - * @protected - */ -goog.testing.AsyncTestCase.prototype.activeTest; - - -/** - * A flag to prevent recursive exception handling. - * @type {boolean} - * @private - */ -goog.testing.AsyncTestCase.prototype.inException_ = false; - - -/** - * Flag used to determine if we can move to the next step in the testing loop. - * @type {boolean} - * @private - */ -goog.testing.AsyncTestCase.prototype.isReady_ = true; - - -/** - * Flag that tells us if there is a function in the call stack that will make - * a call to pump_(). - * @type {boolean} - * @private - */ -goog.testing.AsyncTestCase.prototype.returnWillPump_ = false; - - -/** - * The number of times we have thrown a ControlBreakingException so that we - * know not to complain in our window.onerror handler. In Webkit, window.onerror - * is not supported, and so this counter will keep going up but we won't care - * about it. - * @type {number} - * @private - */ -goog.testing.AsyncTestCase.prototype.numControlExceptionsExpected_ = 0; - - -/** - * Preferred way of creating an AsyncTestCase. Creates one and initializes it - * with the G_testRunner. - * @param {string=} opt_name A descriptive name for the test case. - * @return {goog.testing.AsyncTestCase} The created AsyncTestCase. - */ -goog.testing.AsyncTestCase.createAndInstall = function(opt_name) { - var asyncTestCase = new goog.testing.AsyncTestCase(opt_name); - goog.testing.TestCase.initializeTestRunner(asyncTestCase); - return asyncTestCase; -}; - - -/** - * Informs the testcase not to continue to the next step in the test cycle - * until continueTesting is called. - * @param {string=} opt_name A description of what we are waiting for. - */ -goog.testing.AsyncTestCase.prototype.waitForAsync = function(opt_name) { - this.isReady_ = false; - this.curStepName_ = opt_name || this.curStepName_; - - // Reset the timer that tracks if the async test takes too long. - this.stopTimeoutTimer_(); - this.startTimeoutTimer_(); -}; - - -/** - * Continue with the next step in the test cycle. - */ -goog.testing.AsyncTestCase.prototype.continueTesting = function() { - if (!this.isReady_) { - // We are a potential entry point, so we pump. - this.isReady_ = true; - this.stopTimeoutTimer_(); - // Run this in a setTimeout so that the caller has a chance to call - // waitForAsync() again before we continue. - this.timeout(goog.bind(this.pump_, this, null), 0); - } -}; - - -/** - * Handles an exception thrown by a test. - * @param {*=} opt_e The exception object associated with the failure - * or a string. - * @throws Always throws a ControlBreakingException. - */ -goog.testing.AsyncTestCase.prototype.doAsyncError = function(opt_e) { - // If we've caught an exception that we threw, then just pass it along. This - // can happen if doAsyncError() was called from a call to assert and then - // again by pump_(). - if (opt_e && opt_e.isControlBreakingException) { - throw opt_e; - } - - // Prevent another timeout error from triggering for this test step. - this.stopTimeoutTimer_(); - - // doError() uses test.name. Here, we create a dummy test and give it a more - // helpful name based on the step we're currently on. - var fakeTestObj = new goog.testing.TestCase.Test(this.curStepName_, - goog.nullFunction); - if (this.activeTest) { - fakeTestObj.name = this.activeTest.name + ' [' + fakeTestObj.name + ']'; - } - - // Note: if the test has an error, and then tearDown has an error, they will - // both be reported. - this.doError(fakeTestObj, opt_e); - - // This is a potential entry point, so we pump. We also add in a bit of a - // delay to try and prevent any async behavior from the failed test from - // causing the next test to fail. - this.timeout(goog.bind(this.pump_, this, this.doAsyncErrorTearDown_), - this.timeToSleepAfterFailure); - - // We just caught an exception, so we do not want the code above us on the - // stack to continue executing. If pump_ is in our call-stack, then it will - // batch together multiple errors, so we only increment the count if pump_ is - // not in the stack and let pump_ increment the count when it batches them. - if (!this.returnWillPump_) { - this.numControlExceptionsExpected_ += 1; - this.dbgLog_('doAsynError: numControlExceptionsExpected_ = ' + - this.numControlExceptionsExpected_ + ' and throwing exception.'); - } - - // Copy the error message to ControlBreakingException. - var message = ''; - if (typeof opt_e == 'string') { - message = opt_e; - } else if (opt_e && opt_e.message) { - message = opt_e.message; - } - throw new goog.testing.AsyncTestCase.ControlBreakingException(message); -}; - - -/** - * Sets up the test page and then waits until the test case has been marked - * as ready before executing the tests. - * @override - */ -goog.testing.AsyncTestCase.prototype.runTests = function() { - this.hookAssert_(); - this.hookOnError_(); - - this.setNextStep_(this.doSetUpPage_, 'setUpPage'); - // We are an entry point, so we pump. - this.pump_(); -}; - - -/** - * Starts the tests. - * @override - */ -goog.testing.AsyncTestCase.prototype.cycleTests = function() { - // We are an entry point, so we pump. - this.saveMessage('Start'); - this.setNextStep_(this.doIteration_, 'doIteration'); - this.pump_(); -}; - - -/** - * Finalizes the test case, called when the tests have finished executing. - * @override - */ -goog.testing.AsyncTestCase.prototype.finalize = function() { - this.unhookAll_(); - this.setNextStep_(null, 'finalized'); - goog.testing.AsyncTestCase.superClass_.finalize.call(this); -}; - - -/** - * Enables verbose logging of what is happening inside of the AsyncTestCase. - */ -goog.testing.AsyncTestCase.prototype.enableDebugLogging = function() { - this.enableDebugLogs_ = true; -}; - - -/** - * Logs the given debug message to the console (when enabled). - * @param {string} message The message to log. - * @private - */ -goog.testing.AsyncTestCase.prototype.dbgLog_ = function(message) { - if (this.enableDebugLogs_) { - this.log('AsyncTestCase - ' + message); - } -}; - - -/** - * Wraps doAsyncError() for when we are sure that the test runner has no user - * code above it in the stack. - * @param {string|Error=} opt_e The exception object associated with the - * failure or a string. - * @private - */ -goog.testing.AsyncTestCase.prototype.doTopOfStackAsyncError_ = - function(opt_e) { - /** @preserveTry */ - try { - this.doAsyncError(opt_e); - } catch (e) { - // We know that we are on the top of the stack, so there is no need to - // throw this exception in this case. - if (e.isControlBreakingException) { - this.numControlExceptionsExpected_ -= 1; - this.dbgLog_('doTopOfStackAsyncError_: numControlExceptionsExpected_ = ' + - this.numControlExceptionsExpected_ + ' and catching exception.'); - } else { - throw e; - } - } -}; - - -/** - * Calls the tearDown function, catching any errors, and then moves on to - * the next step in the testing cycle. - * @private - */ -goog.testing.AsyncTestCase.prototype.doAsyncErrorTearDown_ = function() { - if (this.inException_) { - // We get here if tearDown is throwing the error. - // Upon calling continueTesting, the inline function 'doAsyncError' (set - // below) is run. - this.continueTesting(); - } else { - this.inException_ = true; - this.isReady_ = true; - - // The continue point is different depending on if the error happened in - // setUpPage() or in setUp()/test*()/tearDown(). - var stepFuncAfterError = this.nextStepFunc_; - var stepNameAfterError = 'TestCase.execute (after error)'; - if (this.activeTest) { - stepFuncAfterError = this.doIteration_; - stepNameAfterError = 'doIteration (after error)'; - } - - // We must set the next step before calling tearDown. - this.setNextStep_(function() { - this.inException_ = false; - // This is null when an error happens in setUpPage. - this.setNextStep_(stepFuncAfterError, stepNameAfterError); - }, 'doAsyncError'); - - // Call the test's tearDown(). - if (!this.cleanedUp_) { - this.cleanedUp_ = true; - this.tearDown(); - } - } -}; - - -/** - * Replaces the asserts.js assert_() and fail() functions with a wrappers to - * catch the exceptions. - * @private - */ -goog.testing.AsyncTestCase.prototype.hookAssert_ = function() { - if (!this.origAssert_) { - this.origAssert_ = _assert; - this.origFail_ = fail; - var self = this; - _assert = function() { - /** @preserveTry */ - try { - self.origAssert_.apply(this, arguments); - } catch (e) { - self.dbgLog_('Wrapping failed assert()'); - self.doAsyncError(e); - } - }; - fail = function() { - /** @preserveTry */ - try { - self.origFail_.apply(this, arguments); - } catch (e) { - self.dbgLog_('Wrapping fail()'); - self.doAsyncError(e); - } - }; - } -}; - - -/** - * Sets a window.onerror handler for catching exceptions that happen in async - * callbacks. Note that as of Safari 3.1, Safari does not support this. - * @private - */ -goog.testing.AsyncTestCase.prototype.hookOnError_ = function() { - if (!this.origOnError_) { - this.origOnError_ = window.onerror; - var self = this; - window.onerror = function(error, url, line) { - // Ignore exceptions that we threw on purpose. - var cbe = - goog.testing.AsyncTestCase.ControlBreakingException.TO_STRING; - if (String(error).indexOf(cbe) != -1 && - self.numControlExceptionsExpected_) { - self.numControlExceptionsExpected_ -= 1; - self.dbgLog_('window.onerror: numControlExceptionsExpected_ = ' + - self.numControlExceptionsExpected_ + ' and ignoring exception. ' + - error); - // Tell the browser not to compain about the error. - return true; - } else { - self.dbgLog_('window.onerror caught exception.'); - var message = error + '\nURL: ' + url + '\nLine: ' + line; - self.doTopOfStackAsyncError_(message); - // Tell the browser to complain about the error. - return false; - } - }; - } -}; - - -/** - * Unhooks window.onerror and _assert. - * @private - */ -goog.testing.AsyncTestCase.prototype.unhookAll_ = function() { - if (this.origOnError_) { - window.onerror = this.origOnError_; - this.origOnError_ = null; - _assert = this.origAssert_; - this.origAssert_ = null; - fail = this.origFail_; - this.origFail_ = null; - } -}; - - -/** - * Enables the timeout timer. This timer fires unless continueTesting is - * called. - * @private - */ -goog.testing.AsyncTestCase.prototype.startTimeoutTimer_ = function() { - if (!this.timeoutHandle_ && this.stepTimeout > 0) { - this.timeoutHandle_ = this.timeout(goog.bind(function() { - this.dbgLog_('Timeout timer fired with id ' + this.timeoutHandle_); - this.timeoutHandle_ = null; - - this.doTopOfStackAsyncError_('Timed out while waiting for ' + - 'continueTesting() to be called.'); - }, this, null), this.stepTimeout); - this.dbgLog_('Started timeout timer with id ' + this.timeoutHandle_); - } -}; - - -/** - * Disables the timeout timer. - * @private - */ -goog.testing.AsyncTestCase.prototype.stopTimeoutTimer_ = function() { - if (this.timeoutHandle_) { - this.dbgLog_('Clearing timeout timer with id ' + this.timeoutHandle_); - window.clearTimeout(this.timeoutHandle_); - this.timeoutHandle_ = 0; - } -}; - - -/** - * Sets the next function to call in our sequence of async callbacks. - * @param {Function} func The function that executes the next step. - * @param {string} name A description of the next step. - * @private - */ -goog.testing.AsyncTestCase.prototype.setNextStep_ = function(func, name) { - this.nextStepFunc_ = func && goog.bind(func, this); - this.nextStepName_ = name; -}; - - -/** - * Calls the given function, redirecting any exceptions to doAsyncError. - * @param {Function} func The function to call. - * @return {!goog.testing.AsyncTestCase.TopStackFuncResult_} Returns a - * TopStackFuncResult_. - * @private - */ -goog.testing.AsyncTestCase.prototype.callTopOfStackFunc_ = function(func) { - /** @preserveTry */ - try { - func.call(this); - return {controlBreakingExceptionThrown: false, message: ''}; - } catch (e) { - this.dbgLog_('Caught exception in callTopOfStackFunc_'); - /** @preserveTry */ - try { - this.doAsyncError(e); - return {controlBreakingExceptionThrown: false, message: ''}; - } catch (e2) { - if (!e2.isControlBreakingException) { - throw e2; - } - return {controlBreakingExceptionThrown: true, message: e2.message}; - } - } -}; - - -/** - * Calls the next callback when the isReady_ flag is true. - * @param {Function=} opt_doFirst A function to call before pumping. - * @private - * @throws Throws a ControlBreakingException if there were any failing steps. - */ -goog.testing.AsyncTestCase.prototype.pump_ = function(opt_doFirst) { - // If this function is already above us in the call-stack, then we should - // return rather than pumping in order to minimize call-stack depth. - if (!this.returnWillPump_) { - this.setBatchTime(this.now_()); - this.returnWillPump_ = true; - // If we catch an exception in the step, we don't want to return control - // to our caller since there may be non-testcase code in our call stack. - // Eg) - // asyncCallback() { fail(1); fail(2); } - // V - // - ... - // - pump_(); - // We don't want fail(2) to ever be called. - var topFuncResult = {}; - - if (opt_doFirst) { - topFuncResult = this.callTopOfStackFunc_(opt_doFirst); - } - // Note: we don't check for this.running here because it is not set to true - // while executing setUpPage and tearDownPage. - // Also, if isReady_ is false, then one of two things will happen: - // 1. Our timeout callback will be called. - // 2. The tests will call continueTesting(), which will call pump_() again. - while (this.isReady_ && this.nextStepFunc_ && - !topFuncResult.controlBreakingExceptionThrown) { - this.curStepFunc_ = this.nextStepFunc_; - this.curStepName_ = this.nextStepName_; - this.nextStepFunc_ = null; - this.nextStepName_ = ''; - - this.dbgLog_('Performing step: ' + this.curStepName_); - topFuncResult = - this.callTopOfStackFunc_(/** @type {Function} */(this.curStepFunc_)); - - // If the max run time is exceeded call this function again async so as - // not to block the browser. - var delta = this.now_() - this.getBatchTime(); - if (delta > goog.testing.TestCase.MAX_RUN_TIME && - !topFuncResult.controlBreakingExceptionThrown) { - this.saveMessage('Breaking async'); - var self = this; - this.timeout(function() { self.pump_(); }, 100); - break; - } - } - this.returnWillPump_ = false; - // See note at top of this function. - if (topFuncResult.controlBreakingExceptionThrown) { - this.numControlExceptionsExpected_ += 1; - this.dbgLog_('pump: numControlExceptionsExpected_ = ' + - this.numControlExceptionsExpected_ + ' and throwing exception.'); - throw new goog.testing.AsyncTestCase. - ControlBreakingException(topFuncResult.message); - } - } else if (opt_doFirst) { - opt_doFirst.call(this); - } -}; - - -/** - * Sets up the test page and then waits untill the test case has been marked - * as ready before executing the tests. - * @private - */ -goog.testing.AsyncTestCase.prototype.doSetUpPage_ = function() { - this.setNextStep_(this.execute, 'TestCase.execute'); - this.setUpPage(); -}; - - -/** - * Step 1: Move to the next test. - * @private - */ -goog.testing.AsyncTestCase.prototype.doIteration_ = function() { - this.activeTest = this.next(); - if (this.activeTest && this.running) { - this.result_.runCount++; - this.setNextStep_(this.doSetUp_, 'setUp'); - } else { - // All tests done. - this.finalize(); - } -}; - - -/** - * Step 2: Call setUp(). - * @private - */ -goog.testing.AsyncTestCase.prototype.doSetUp_ = function() { - this.log('Running test: ' + this.activeTest.name); - this.cleanedUp_ = false; - this.setNextStep_(this.doExecute_, this.activeTest.name); - this.setUp(); -}; - - -/** - * Step 3: Call test.execute(). - * @private - */ -goog.testing.AsyncTestCase.prototype.doExecute_ = function() { - this.setNextStep_(this.doTearDown_, 'tearDown'); - this.activeTest.execute(); -}; - - -/** - * Step 4: Call tearDown(). - * @private - */ -goog.testing.AsyncTestCase.prototype.doTearDown_ = function() { - this.cleanedUp_ = true; - this.setNextStep_(this.doNext_, 'doNext'); - this.tearDown(); -}; - - -/** - * Step 5: Call doSuccess() - * @private - */ -goog.testing.AsyncTestCase.prototype.doNext_ = function() { - this.setNextStep_(this.doIteration_, 'doIteration'); - this.doSuccess(/** @type {goog.testing.TestCase.Test} */(this.activeTest)); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_async_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_async_test.html.svn-base deleted file mode 100644 index 937417e..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_async_test.html.svn-base +++ /dev/null @@ -1,102 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2009 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- -Author: agrieve@google.com (Andrew Grieve) - -This tests that the AsyncTestCase can handle asynchronous behaviour in: - setUpPage(), - setUp(), - test*(), - tearDown() ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.AsyncTestCase Asyncronous Tests</title> - <script src="../base.js"></script> - <script type="text/javascript"> - goog.require('goog.testing.AsyncTestCase'); - goog.require('goog.testing.jsunit'); - </script> -</head> -<body> - <script> - // Has the setUp() function been called. - var setUpCalled = false; - // Has the current test function completed. This helps us to ensure that - // the next test is not started before the previous completed. - var curTestIsDone = true; - // Use an asynchronous test runner for our tests. - var asyncTestCase = - goog.testing.AsyncTestCase.createAndInstall(document.title); - - /** - * Uses window.setTimeout() to perform asynchronous behaviour and uses - * asyncTestCase.waitForAsync() and asyncTestCase.continueTesting() to mark - * the beginning and end of it. - * @param {number} numAsyncCalls The number of asynchronous calls to make. - * @param {string} name The name of the current step. - */ - function doAsyncStuff(numAsyncCalls, name) { - if (numAsyncCalls > 0) { - curTestIsDone = false; - asyncTestCase.waitForAsync('doAsyncStuff-' + name + '(' + numAsyncCalls - + ')'); - window.setTimeout(function() { - doAsyncStuff(numAsyncCalls - 1, name); - }, 0); - } else { - curTestIsDone = true; - asyncTestCase.continueTesting(); - } - } - - function setUpPage() { - debug('setUpPage was called.'); - doAsyncStuff(3, 'setUpPage'); - } - function setUp() { - assertTrue(curTestIsDone); - doAsyncStuff(3, 'setUp'); - } - function tearDown() { - assertTrue(curTestIsDone); - } - function test1() { - assertTrue(curTestIsDone); - doAsyncStuff(1, 'test1'); - } - function test2_asyncContinueThenWait() { - var activeTest = asyncTestCase.activeTest_; - function async1() { - asyncTestCase.continueTesting(); - asyncTestCase.waitForAsync('2'); - window.setTimeout(async2, 0); - } - function async2() { - asyncTestCase.continueTesting(); - assertEquals('Did not wait for inner waitForAsync', - activeTest, - asyncTestCase.activeTest_); - } - asyncTestCase.waitForAsync('1'); - window.setTimeout(async1, 0); - } - function test3() { - assertTrue(curTestIsDone); - doAsyncStuff(2, 'test3'); - } - - function tearDownPage() { - debug('tearDownPage was called.'); - assertTrue(curTestIsDone); - } - - </script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_noasync_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_noasync_test.html.svn-base deleted file mode 100644 index edbf55d..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_noasync_test.html.svn-base +++ /dev/null @@ -1,98 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2009 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- -Author: agrieve@google.com (Andrew Grieve) - -This tests that the AsyncTestCase can handle synchronous behaviour in: - setUpPage(), - setUp(), - test*(), - tearDown() -It is the same test as asynctestcase_async_test.html, except that it uses a mock -version of window.setTimeout() to eliminate all asynchronous calls. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> - <title>Closure Unit Tests - goog.testing.AsyncTestCase Synchronous Tests</title> - <script src="../base.js"></script> - <script type="text/javascript"> - goog.require('goog.testing.AsyncTestCase'); - goog.require('goog.testing.jsunit'); - </script> -</head> -<body> - <script> - // Has the setUp() function been called. - var setUpCalled = false; - // Has the current test function completed. This helps us to ensure that the - // next test is not started before the previous completed. - var curTestIsDone = true; - // For restoring it later. - var oldTimeout = window.setTimeout; - // Use an asynchronous test runner for our tests. - var asyncTestCase = - goog.testing.AsyncTestCase.createAndInstall(document.title); - - /** - * Uses window.setTimeout() to perform asynchronous behaviour and uses - * asyncTestCase.waitForAsync() and asyncTestCase.continueTesting() to mark - * the beginning and end of it. - * @param {number} numAsyncCalls The number of asynchronous calls to make. - * @param {string} name The name of the current step. - */ - function doAsyncStuff(numAsyncCalls, name) { - if (numAsyncCalls > 0) { - curTestIsDone = false; - asyncTestCase.waitForAsync('doAsyncStuff-' + name + '(' + numAsyncCalls - + ')'); - window.setTimeout(function() { - doAsyncStuff(numAsyncCalls - 1, name); - }, 0); - } else { - curTestIsDone = true; - asyncTestCase.continueTesting(); - } - } - - function setUpPage() { - debug('setUpPage was called.'); - // Don't do anything asynchronously. - window.setTimeout = function(callback, time) { - callback(); - }; - doAsyncStuff(3, 'setUpPage'); - } - function setUp() { - assertTrue(curTestIsDone); - doAsyncStuff(3, 'setUp'); - } - function tearDown() { - assertTrue(curTestIsDone); - } - function test1() { - assertTrue(curTestIsDone); - doAsyncStuff(1, 'test1'); - } - function test2() { - assertTrue(curTestIsDone); - doAsyncStuff(2, 'test2'); - } - function test3() { - assertTrue(curTestIsDone); - doAsyncStuff(5, 'test3'); - } - function tearDownPage() { - debug('tearDownPage was called.'); - assertTrue(curTestIsDone); - window.setTimeout = oldTimeout; - } - - </script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_test.html.svn-base deleted file mode 100644 index a3eabef..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/asynctestcase_test.html.svn-base +++ /dev/null @@ -1,58 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2011 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.asynctestcase</title> -<script src="../base.js"></script> -<script> - goog.require('goog.debug.Error'); - goog.require('goog.testing.AsyncTestCase'); - goog.require('goog.testing.AsyncTestCase.ControlBreakingException'); - goog.require('goog.testing.asserts'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - - -function testControlBreakingExceptionThrown() { - var asyncTestCase = new goog.testing.AsyncTestCase(); - - // doAsyncError with no message. - try { - asyncTestCase.doAsyncError(); - } catch (e) { - assertTrue(e.isControlBreakingException); - assertEquals('', e.message); - } - - // doAsyncError with string. - var errorMessage1 = 'Error message 1'; - try { - asyncTestCase.doAsyncError(errorMessage1); - } catch (e) { - assertTrue(e.isControlBreakingException); - assertEquals(errorMessage1, e.message); - } - - // doAsyncError with error. - var errorMessage2 = 'Error message 2'; - try { - var error = new goog.debug.Error(errorMessage2); - asyncTestCase.doAsyncError(error); - } catch (e) { - assertTrue(e.isControlBreakingException); - assertEquals(errorMessage2, e.message); - } -} - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/benchmark.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/benchmark.js.svn-base deleted file mode 100644 index 8c38ec8..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/benchmark.js.svn-base +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -goog.provide('goog.testing.benchmark'); - -goog.require('goog.dom'); -goog.require('goog.dom.TagName'); -goog.require('goog.testing.PerformanceTable'); -goog.require('goog.testing.PerformanceTimer'); -goog.require('goog.testing.TestCase'); - - -/** - * Run the benchmarks. - * @private - */ -goog.testing.benchmark.run_ = function() { - // Parse the 'times' query parameter if it's set. - var times = 200; - var search = window.location.search; - var timesMatch = search.match(/(?:\?|&)times=([^?&]+)/i); - if (timesMatch) { - times = Number(timesMatch[1]); - } - - var prefix = 'benchmark'; - - // First, get the functions. - var testSource = goog.testing.TestCase.getGlobals(prefix); - - var benchmarks = {}; - var names = []; - - for (var name in testSource) { - try { - var ref = testSource[name]; - } catch (ex) { - // NOTE(user): When running tests from a file:// URL on Firefox 3.5 - // for Windows, any reference to window.sessionStorage raises - // an "Operation is not supported" exception. Ignore any exceptions raised - // by simply accessing global properties. - } - - if ((new RegExp('^' + prefix)).test(name) && goog.isFunction(ref)) { - benchmarks[name] = ref; - names.push(name); - } - } - - document.body.appendChild( - goog.dom.createTextNode( - 'Running ' + names.length + ' benchmarks ' + times + ' times each.')); - document.body.appendChild(goog.dom.createElement(goog.dom.TagName.BR)); - - names.sort(); - - // Build a table and timer. - var performanceTimer = new goog.testing.PerformanceTimer(times); - performanceTimer.setDiscardOutliers(true); - - var performanceTable = new goog.testing.PerformanceTable(document.body, - performanceTimer, 2); - - // Next, run the benchmarks. - for (var i = 0; i < names.length; i++) { - performanceTable.run(benchmarks[names[i]], names[i]); - } -}; - - -/** - * Onload handler that runs the benchmarks. - */ -window.onload = function() { - goog.testing.benchmark.run_(); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/continuationtestcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/continuationtestcase.js.svn-base deleted file mode 100644 index 684e7da..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/continuationtestcase.js.svn-base +++ /dev/null @@ -1,682 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Defines test classes for tests that can wait for conditions. - * - * Normal unit tests must complete their test logic within a single function - * execution. This is ideal for most tests, but makes it difficult to test - * routines that require real time to complete. The tests and TestCase in this - * file allow for tests that can wait until a condition is true before - * continuing execution. - * - * Each test has the typical three phases of execution: setUp, the test itself, - * and tearDown. During each phase, the test function may add wait conditions, - * which result in new test steps being added for that phase. All steps in a - * given phase must complete before moving on to the next phase. An error in - * any phase will stop that test and report the error to the test runner. - * - * This class should not be used where adequate mocks exist. Time-based routines - * should use the MockClock, which runs much faster and provides equivalent - * results. Continuation tests should be used for testing code that depends on - * browser behaviors that are difficult to mock. For example, testing code that - * relies on Iframe load events, event or layout code that requires a setTimeout - * to become valid, and other browser-dependent native object interactions for - * which mocks are insufficient. - * - * Sample usage: - * - * <pre> - * var testCase = new goog.testing.ContinuationTestCase(); - * testCase.autoDiscoverTests(); - * - * if (typeof G_testRunner != 'undefined') { - * G_testRunner.initialize(testCase); - * } - * - * function testWaiting() { - * var someVar = true; - * waitForTimeout(function() { - * assertTrue(someVar) - * }, 500); - * } - * - * function testWaitForEvent() { - * var et = goog.events.EventTarget(); - * waitForEvent(et, 'test', function() { - * // Test step runs after the event fires. - * }) - * et.dispatchEvent(et, 'test'); - * } - * - * function testWaitForCondition() { - * var counter = 0; - * - * waitForCondition(function() { - * // This function is evaluated periodically until it returns true, or it - * // times out. - * return ++counter >= 3; - * }, function() { - * // This test step is run once the condition becomes true. - * assertEquals(3, counter); - * }); - * } - * </pre> - * - */ - - -goog.provide('goog.testing.ContinuationTestCase'); -goog.provide('goog.testing.ContinuationTestCase.Step'); -goog.provide('goog.testing.ContinuationTestCase.Test'); - -goog.require('goog.array'); -goog.require('goog.events.EventHandler'); -goog.require('goog.testing.TestCase'); -goog.require('goog.testing.TestCase.Test'); -goog.require('goog.testing.asserts'); - - - -/** - * Constructs a test case that supports tests with continuations. Test functions - * may issue "wait" commands that suspend the test temporarily and continue once - * the wait condition is met. - * - * @param {string=} opt_name Optional name for the test case. - * @constructor - * @extends {goog.testing.TestCase} - */ -goog.testing.ContinuationTestCase = function(opt_name) { - goog.testing.TestCase.call(this, opt_name); - - /** - * An event handler for waiting on Closure or browser events during tests. - * @type {goog.events.EventHandler} - * @private - */ - this.handler_ = new goog.events.EventHandler(this); -}; -goog.inherits(goog.testing.ContinuationTestCase, goog.testing.TestCase); - - -/** - * The default maximum time to wait for a single test step in milliseconds. - * @type {number} - */ -goog.testing.ContinuationTestCase.MAX_TIMEOUT = 1000; - - -/** - * Lock used to prevent multiple test steps from running recursively. - * @type {boolean} - * @private - */ -goog.testing.ContinuationTestCase.locked_ = false; - - -/** - * The current test being run. - * @type {goog.testing.ContinuationTestCase.Test} - * @private - */ -goog.testing.ContinuationTestCase.prototype.currentTest_ = null; - - -/** - * Enables or disables the wait functions in the global scope. - * @param {boolean} enable Whether the wait functions should be exported. - * @private - */ -goog.testing.ContinuationTestCase.prototype.enableWaitFunctions_ = - function(enable) { - if (enable) { - goog.exportSymbol('waitForCondition', - goog.bind(this.waitForCondition, this)); - goog.exportSymbol('waitForEvent', goog.bind(this.waitForEvent, this)); - goog.exportSymbol('waitForTimeout', goog.bind(this.waitForTimeout, this)); - } else { - // Internet Explorer doesn't allow deletion of properties on the window. - goog.global['waitForCondition'] = undefined; - goog.global['waitForEvent'] = undefined; - goog.global['waitForTimeout'] = undefined; - } -}; - - -/** @override */ -goog.testing.ContinuationTestCase.prototype.runTests = function() { - this.enableWaitFunctions_(true); - goog.testing.ContinuationTestCase.superClass_.runTests.call(this); -}; - - -/** @override */ -goog.testing.ContinuationTestCase.prototype.finalize = function() { - this.enableWaitFunctions_(false); - goog.testing.ContinuationTestCase.superClass_.finalize.call(this); -}; - - -/** @override */ -goog.testing.ContinuationTestCase.prototype.cycleTests = function() { - // Get the next test in the queue. - if (!this.currentTest_) { - this.currentTest_ = this.createNextTest_(); - } - - // Run the next step of the current test, or exit if all tests are complete. - if (this.currentTest_) { - this.runNextStep_(); - } else { - this.finalize(); - } -}; - - -/** - * Creates the next test in the queue. - * @return {goog.testing.ContinuationTestCase.Test} The next test to execute, or - * null if no pending tests remain. - * @private - */ -goog.testing.ContinuationTestCase.prototype.createNextTest_ = function() { - var test = this.next(); - if (!test) { - return null; - } - - - var name = test.name; - goog.testing.TestCase.currentTestName = name; - this.result_.runCount++; - this.log('Running test: ' + name); - - return new goog.testing.ContinuationTestCase.Test( - new goog.testing.TestCase.Test(name, this.setUp, this), - test, - new goog.testing.TestCase.Test(name, this.tearDown, this)); -}; - - -/** - * Cleans up a finished test and cycles to the next test. - * @private - */ -goog.testing.ContinuationTestCase.prototype.finishTest_ = function() { - var err = this.currentTest_.getError(); - if (err) { - this.doError(this.currentTest_, err); - } else { - this.doSuccess(this.currentTest_); - } - - goog.testing.TestCase.currentTestName = null; - this.currentTest_ = null; - this.locked_ = false; - this.handler_.removeAll(); - - this.timeout(goog.bind(this.cycleTests, this), 0); -}; - - -/** - * Executes the next step in the current phase, advancing through each phase as - * all steps are completed. - * @private - */ -goog.testing.ContinuationTestCase.prototype.runNextStep_ = function() { - if (this.locked_) { - // Attempting to run a step before the previous step has finished. Try again - // after that step has released the lock. - return; - } - - var phase = this.currentTest_.getCurrentPhase(); - - if (!phase || !phase.length) { - // No more steps for this test. - this.finishTest_(); - return; - } - - // Find the next step that is not in a wait state. - var stepIndex = goog.array.findIndex(phase, function(step) { - return !step.waiting; - }); - - if (stepIndex < 0) { - // All active steps are currently waiting. Return until one wakes up. - return; - } - - this.locked_ = true; - var step = phase[stepIndex]; - - try { - step.execute(); - // Remove the successfully completed step. If an error is thrown, all steps - // will be removed for this phase. - goog.array.removeAt(phase, stepIndex); - - } catch (e) { - this.currentTest_.setError(e); - - // An assertion has failed, or an exception was raised. Clear the current - // phase, whether it is setUp, test, or tearDown. - this.currentTest_.cancelCurrentPhase(); - - // Cancel the setUp and test phase no matter where the error occurred. The - // tearDown phase will still run if it has pending steps. - this.currentTest_.cancelTestPhase(); - } - - this.locked_ = false; - this.runNextStep_(); -}; - - -/** - * Creates a new test step that will run after a user-specified timeout. - * @param {Function} continuation The test function to invoke after the timeout. - * @param {number=} opt_duration The length of the timeout in milliseconds. - */ -goog.testing.ContinuationTestCase.prototype.waitForTimeout = - function(continuation, opt_duration) { - var step = this.addStep_(continuation); - step.setTimeout(goog.bind(this.handleComplete_, this, step), - opt_duration || 0); -}; - - -/** - * Creates a new test step that will run after an event has fired. If the event - * does not fire within a reasonable timeout, the test will fail. - * @param {goog.events.EventTarget|EventTarget} eventTarget The target that will - * fire the event. - * @param {string} eventType The type of event to listen for. - * @param {Function} continuation The test function to invoke after the event - * fires. - */ -goog.testing.ContinuationTestCase.prototype.waitForEvent = function( - eventTarget, - eventType, - continuation) { - - var step = this.addStep_(continuation); - - var duration = goog.testing.ContinuationTestCase.MAX_TIMEOUT; - step.setTimeout(goog.bind(this.handleTimeout_, this, step, duration), - duration); - - this.handler_.listenOnce(eventTarget, - eventType, - goog.bind(this.handleComplete_, this, step)); -}; - - -/** - * Creates a new test step which will run once a condition becomes true. The - * condition will be polled at a user-specified interval until it becomes true, - * or until a maximum timeout is reached. - * @param {Function} condition The condition to poll. - * @param {Function} continuation The test code to evaluate once the condition - * becomes true. - * @param {number=} opt_interval The polling interval in milliseconds. - * @param {number=} opt_maxTimeout The maximum amount of time to wait for the - * condition in milliseconds (defaults to 1000). - */ -goog.testing.ContinuationTestCase.prototype.waitForCondition = function( - condition, - continuation, - opt_interval, - opt_maxTimeout) { - - var interval = opt_interval || 100; - var timeout = opt_maxTimeout || goog.testing.ContinuationTestCase.MAX_TIMEOUT; - - var step = this.addStep_(continuation); - this.testCondition_(step, condition, goog.now(), interval, timeout); -}; - - -/** - * Creates a new asynchronous test step which will be added to the current test - * phase. - * @param {Function} func The test function that will be executed for this step. - * @return {goog.testing.ContinuationTestCase.Step} A new test step. - * @private - */ -goog.testing.ContinuationTestCase.prototype.addStep_ = function(func) { - if (!this.currentTest_) { - throw Error('Cannot add test steps outside of a running test.'); - } - - var step = new goog.testing.ContinuationTestCase.Step( - this.currentTest_.name, - func, - this.currentTest_.scope); - this.currentTest_.addStep(step); - return step; -}; - - -/** - * Handles completion of a step's wait condition. Advances the test, allowing - * the step's test method to run. - * @param {goog.testing.ContinuationTestCase.Step} step The step that has - * finished waiting. - * @private - */ -goog.testing.ContinuationTestCase.prototype.handleComplete_ = function(step) { - step.clearTimeout(); - step.waiting = false; - this.runNextStep_(); -}; - - -/** - * Handles the timeout event for a step that has exceeded the maximum time. This - * causes the current test to fail. - * @param {goog.testing.ContinuationTestCase.Step} step The timed-out step. - * @param {number} duration The length of the timeout in milliseconds. - * @private - */ -goog.testing.ContinuationTestCase.prototype.handleTimeout_ = - function(step, duration) { - step.ref = function() { - fail('Continuation timed out after ' + duration + 'ms.'); - }; - - // Since the test is failing, cancel any other pending event listeners. - this.handler_.removeAll(); - this.handleComplete_(step); -}; - - -/** - * Tests a wait condition and executes the associated test step once the - * condition is true. - * - * If the condition does not become true before the maximum duration, the - * interval will stop and the test step will fail in the kill timer. - * - * @param {goog.testing.ContinuationTestCase.Step} step The waiting test step. - * @param {Function} condition The test condition. - * @param {number} startTime Time when the test step began waiting. - * @param {number} interval The duration in milliseconds to wait between tests. - * @param {number} timeout The maximum amount of time to wait for the condition - * to become true. Measured from the startTime in milliseconds. - * @private - */ -goog.testing.ContinuationTestCase.prototype.testCondition_ = function( - step, - condition, - startTime, - interval, - timeout) { - - var duration = goog.now() - startTime; - - if (condition()) { - this.handleComplete_(step); - } else if (duration < timeout) { - step.setTimeout(goog.bind(this.testCondition_, - this, - step, - condition, - startTime, - interval, - timeout), - interval); - } else { - this.handleTimeout_(step, duration); - } -}; - - - -/** - * Creates a continuation test case, which consists of multiple test steps that - * occur in several phases. - * - * The steps are distributed between setUp, test, and tearDown phases. During - * the execution of each step, 0 or more steps may be added to the current - * phase. Once all steps in a phase have completed, the next phase will be - * executed. - * - * If any errors occur (such as an assertion failure), the setUp and Test phases - * will be cancelled immediately. The tearDown phase will always start, but may - * be cancelled as well if it raises an error. - * - * @param {goog.testing.TestCase.Test} setUp A setUp test method to run before - * the main test phase. - * @param {goog.testing.TestCase.Test} test A test method to run. - * @param {goog.testing.TestCase.Test} tearDown A tearDown test method to run - * after the test method completes or fails. - * @constructor - * @extends {goog.testing.TestCase.Test} - */ -goog.testing.ContinuationTestCase.Test = function(setUp, test, tearDown) { - // This test container has a name, but no evaluation function or scope. - goog.testing.TestCase.Test.call(this, test.name, null, null); - - /** - * The list of test steps to run during setUp. - * @type {Array.<goog.testing.TestCase.Test>} - * @private - */ - this.setUp_ = [setUp]; - - /** - * The list of test steps to run for the actual test. - * @type {Array.<goog.testing.TestCase.Test>} - * @private - */ - this.test_ = [test]; - - /** - * The list of test steps to run during the tearDown phase. - * @type {Array.<goog.testing.TestCase.Test>} - * @private - */ - this.tearDown_ = [tearDown]; -}; -goog.inherits(goog.testing.ContinuationTestCase.Test, - goog.testing.TestCase.Test); - - -/** - * The first error encountered during the test run, if any. - * @type {Error} - * @private - */ -goog.testing.ContinuationTestCase.Test.prototype.error_ = null; - - -/** - * @return {Error} The first error to be raised during the test run or null if - * no errors occurred. - */ -goog.testing.ContinuationTestCase.Test.prototype.getError = function() { - return this.error_; -}; - - -/** - * Sets an error for the test so it can be reported. Only the first error set - * during a test will be reported. Additional errors that occur in later test - * phases will be discarded. - * @param {Error} e An error. - */ -goog.testing.ContinuationTestCase.Test.prototype.setError = function(e) { - this.error_ = this.error_ || e; -}; - - -/** - * @return {Array.<goog.testing.TestCase.Test>} The current phase of steps - * being processed. Returns null if all steps have been completed. - */ -goog.testing.ContinuationTestCase.Test.prototype.getCurrentPhase = function() { - if (this.setUp_.length) { - return this.setUp_; - } - - if (this.test_.length) { - return this.test_; - } - - if (this.tearDown_.length) { - return this.tearDown_; - } - - return null; -}; - - -/** - * Adds a new test step to the end of the current phase. The new step will wait - * for a condition to be met before running, or will fail after a timeout. - * @param {goog.testing.ContinuationTestCase.Step} step The test step to add. - */ -goog.testing.ContinuationTestCase.Test.prototype.addStep = function(step) { - var phase = this.getCurrentPhase(); - if (phase) { - phase.push(step); - } else { - throw Error('Attempted to add a step to a completed test.'); - } -}; - - -/** - * Cancels all remaining steps in the current phase. Called after an error in - * any phase occurs. - */ -goog.testing.ContinuationTestCase.Test.prototype.cancelCurrentPhase = - function() { - this.cancelPhase_(this.getCurrentPhase()); -}; - - -/** - * Skips the rest of the setUp and test phases, but leaves the tearDown phase to - * clean up. - */ -goog.testing.ContinuationTestCase.Test.prototype.cancelTestPhase = function() { - this.cancelPhase_(this.setUp_); - this.cancelPhase_(this.test_); -}; - - -/** - * Clears a test phase and cancels any pending steps found. - * @param {Array.<goog.testing.TestCase.Test>} phase A list of test steps. - * @private - */ -goog.testing.ContinuationTestCase.Test.prototype.cancelPhase_ = - function(phase) { - while (phase && phase.length) { - var step = phase.pop(); - if (step instanceof goog.testing.ContinuationTestCase.Step) { - step.clearTimeout(); - } - } -}; - - - -/** - * Constructs a single step in a larger continuation test. Each step is similar - * to a typical TestCase test, except it may wait for an event or timeout to - * occur before running the test function. - * - * @param {string} name The test name. - * @param {Function} ref The test function to run. - * @param {Object=} opt_scope The object context to run the test in. - * @constructor - * @extends {goog.testing.TestCase.Test} - */ -goog.testing.ContinuationTestCase.Step = function(name, ref, opt_scope) { - goog.testing.TestCase.Test.call(this, name, ref, opt_scope); -}; -goog.inherits(goog.testing.ContinuationTestCase.Step, - goog.testing.TestCase.Test); - - -/** - * Whether the step is currently waiting for a condition to continue. All new - * steps begin in wait state. - * @type {boolean} - */ -goog.testing.ContinuationTestCase.Step.prototype.waiting = true; - - -/** - * A saved reference to window.clearTimeout so that MockClock or other overrides - * don't affect continuation timeouts. - * @type {Function} - * @private - */ -goog.testing.ContinuationTestCase.Step.protectedClearTimeout_ = - window.clearTimeout; - - -/** - * A saved reference to window.setTimeout so that MockClock or other overrides - * don't affect continuation timeouts. - * @type {Function} - * @private - */ -goog.testing.ContinuationTestCase.Step.protectedSetTimeout_ = window.setTimeout; - - -/** - * Key to this step's timeout. If the step is waiting for an event, the timeout - * will be used as a kill timer. If the step is waiting - * @type {number} - * @private - */ -goog.testing.ContinuationTestCase.Step.prototype.timeout_; - - -/** - * Starts a timeout for this step. Each step may have only one timeout active at - * a time. - * @param {Function} func The function to call after the timeout. - * @param {number} duration The number of milliseconds to wait before invoking - * the function. - */ -goog.testing.ContinuationTestCase.Step.prototype.setTimeout = - function(func, duration) { - - this.clearTimeout(); - - var setTimeout = goog.testing.ContinuationTestCase.Step.protectedSetTimeout_; - this.timeout_ = setTimeout(func, duration); -}; - - -/** - * Clears the current timeout if it is active. - */ -goog.testing.ContinuationTestCase.Step.prototype.clearTimeout = function() { - if (this.timeout_) { - var clear = goog.testing.ContinuationTestCase.Step.protectedClearTimeout_; - - clear(this.timeout_); - delete this.timeout_; - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/continuationtestcase_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/continuationtestcase_test.html.svn-base deleted file mode 100644 index 910e9b1..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/continuationtestcase_test.html.svn-base +++ /dev/null @@ -1,349 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2009 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.ContinuationTestCase</title> -<script src="../base.js"></script> -<script> -goog.require('goog.events'); -goog.require('goog.events.EventTarget'); -goog.require('goog.testing.ContinuationTestCase'); -goog.require('goog.testing.MockClock'); -goog.require('goog.testing.PropertyReplacer'); -goog.require('goog.testing.TestCase.Test'); -goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> -/** - * @fileoverview This test file uses the ContinuationTestCase to test itself, - * which is a little confusing. It's also difficult to write a truly effective - * test, since testing a failure causes an actual failure in the test runner. - * All tests have been manually verified using a sophisticated combination of - * alerts and false assertions. - */ - -var testCase = new goog.testing.ContinuationTestCase('Continuation Test Case'); -testCase.autoDiscoverTests(); - -// Standalone Closure Test Runner. -if (typeof G_testRunner != 'undefined') { - G_testRunner.initialize(testCase); -} - - -var clock = new goog.testing.MockClock(); -var count = 0; -var stubs = new goog.testing.PropertyReplacer(); - - -function setUpPage() { - count = testCase.getCount(); -} - - -/** - * Resets the mock clock. Includes a wait step to verify that setUp routines - * can contain continuations. - */ -function setUp() { - waitForTimeout(function() { - // Pointless assertion to verify that setUp methods can contain waits. - assertEquals(count, testCase.getCount()); - }, 0); - - clock.reset(); -} - - -/** - * Uninstalls the mock clock if it was installed, and restores the Step timeout - * functions to the default window implementations. - */ -function tearDown() { - clock.uninstall(); - stubs.reset(); - - waitForTimeout(function() { - // Pointless assertion to verify that tearDown methods can contain waits. - assertTrue(testCase.now_() >= testCase.startTime_); - }, 0); -} - - -/** - * Installs the Mock Clock and replaces the Step timeouts with the mock - * implementations. - */ -function installMockClock() { - clock.install(); - - // Overwrite the "protected" setTimeout and clearTimeout with the versions - // replaced by MockClock. Normal tests should never do this, but we need to - // test the ContinuationTest itself. - stubs.set(goog.testing.ContinuationTestCase.Step, 'protectedClearTimeout_', - window.clearTimeout); - stubs.set(goog.testing.ContinuationTestCase.Step, 'protectedSetTimeout_', - window.setTimeout); -} - - -/** - * @return {goog.testing.ContinuationTestCase.Step} A generic step in a - * continuation test. - */ -function getSampleStep() { - return new goog.testing.ContinuationTestCase.Step('test', function() {}); -} - - -/** - * @return {goog.testing.ContinuationTestCase.Test} A simple continuation test - * with generic setUp, test, and tearDown functions. - */ -function getSampleTest() { - var setupStep = new goog.testing.TestCase.Test('setup', function() {}) - var testStep = new goog.testing.TestCase.Test('test', function() {}) - var teardownStep = new goog.testing.TestCase.Test('teardown', function() {}) - - return new goog.testing.ContinuationTestCase.Test(setupStep, - testStep, - teardownStep); -} - - -function testStepWaiting() { - var step = getSampleStep(); - assertTrue(step.waiting); -} - - -function testStepSetTimeout() { - installMockClock(); - var step = getSampleStep(); - - var timeoutReached = false; - step.setTimeout(function() {timeoutReached = true}, 100); - - clock.tick(50); - assertFalse(timeoutReached); - clock.tick(50); - assertTrue(timeoutReached); -} - - -function testStepClearTimeout() { - var step = new goog.testing.ContinuationTestCase.Step('test', function() {}); - - var timeoutReached = false; - step.setTimeout(function() {timeoutReached = true}, 100); - - clock.tick(50); - assertFalse(timeoutReached); - step.clearTimeout(); - clock.tick(50); - assertFalse(timeoutReached); -} - - -function testTestPhases() { - var test = getSampleTest(); - - assertEquals('setup', test.getCurrentPhase()[0].name); - test.cancelCurrentPhase(); - - assertEquals('test', test.getCurrentPhase()[0].name); - test.cancelCurrentPhase(); - - assertEquals('teardown', test.getCurrentPhase()[0].name); - test.cancelCurrentPhase(); - - assertNull(test.getCurrentPhase()); -} - - -function testTestSetError() { - var test = getSampleTest(); - - var error1 = new Error('Oh noes!'); - var error2 = new Error('B0rken.'); - - assertNull(test.getError()); - test.setError(error1); - assertEquals(error1, test.getError()); - test.setError(error2); - assertEquals('Once an error has been set, it should not be overwritten.', - error1, test.getError()); -} - - -function testAddStep() { - var test = getSampleTest(); - var step = getSampleStep(); - - // Try adding a step to each phase and then cancelling the phase. - for (var i = 0; i < 3; i++) { - assertEquals(1, test.getCurrentPhase().length); - test.addStep(step); - - assertEquals(2, test.getCurrentPhase().length); - assertEquals(step, test.getCurrentPhase()[1]); - test.cancelCurrentPhase(); - } - - assertNull(test.getCurrentPhase()); -} - - -function testCancelTestPhase() { - var test = getSampleTest(); - - test.cancelTestPhase(); - assertEquals('teardown', test.getCurrentPhase()[0].name); - - test = getSampleTest(); - test.cancelCurrentPhase(); - test.cancelTestPhase(); - assertEquals('teardown', test.getCurrentPhase()[0].name); - - test = getSampleTest(); - test.cancelTestPhase(); - test.cancelTestPhase(); - assertEquals('teardown', test.getCurrentPhase()[0].name); -} - - -function testWaitForTimeout() { - var reachedA = false; - var reachedB = false; - var reachedC = false; - - waitForTimeout(function a() { - reachedA = true; - - assertTrue('A must be true at callback a.', reachedA); - assertFalse('B must be false at callback a.', reachedB); - assertFalse('C must be false at callback a.', reachedC); - }, 10); - - waitForTimeout(function b() { - reachedB = true; - - assertTrue('A must be true at callback b.', reachedA); - assertTrue('B must be true at callback b.', reachedB); - assertFalse('C must be false at callback b.', reachedC); - }, 20); - - waitForTimeout(function c() { - reachedC = true; - - assertTrue('A must be true at callback c.', reachedA); - assertTrue('B must be true at callback c.', reachedB); - assertTrue('C must be true at callback c.', reachedC); - }, 20); - - assertFalse('a', reachedA); - assertFalse('b', reachedB); - assertFalse('c', reachedC); -} - - -function testWaitForEvent() { - var et = new goog.events.EventTarget(); - - var eventFired = false; - goog.events.listen(et, 'testPrefire', function() { - eventFired = true; - et.dispatchEvent('test'); - }); - - waitForEvent(et, 'test', function() { - assertTrue(eventFired); - }); - - et.dispatchEvent('testPrefire'); -} - - -function testWaitForCondition() { - var counter = 0; - - waitForCondition(function() { - return ++counter >= 3; - }, function() { - assertEquals(3, counter); - }, 10, 100); -} - - -function testOutOfOrderWaits() { - var counter = 0; - waitForTimeout(function() {assertEquals(5, ++counter);}, 50); - waitForTimeout(function() {assertEquals(1, ++counter);}, 10); - waitForTimeout(function() {assertEquals(3, ++counter);}, 30); - waitForTimeout(function() {assertEquals(2, ++counter);}, 20); - waitForTimeout(function() {assertEquals(4, ++counter);}, 40); -} - - -/* - * Any of the test functions below (except the condition check passed into - * waitForCondition) can raise an assertion successfully. Any level of nested - * test steps should be possible, in any configuration. - */ - -var testObj; - - -function testCrazyNestedWaitFunction() { - testObj = { - lock: true, - et: new goog.events.EventTarget(), - steps: 0 - } - - waitForTimeout(handleTimeout, 10); - waitForEvent(testObj.et, 'test', handleEvent); - waitForCondition(condition, handleCondition, 1); -} - -function handleTimeout() { - testObj.steps++; - assertEquals('handleTimeout should be called first.', 1, testObj.steps); - waitForTimeout(fireEvent, 10); -} - -function fireEvent() { - testObj.steps++; - assertEquals('fireEvent should be called second.', 2, testObj.steps); - testObj.et.dispatchEvent('test'); -} - -function handleEvent() { - testObj.steps++; - assertEquals('handleEvent should be called third.', 3, testObj.steps); - testObj.lock = false; -} - -function condition() { - return !testObj.lock; -} - -function handleCondition() { - assertFalse(testObj.lock); - testObj.steps++; - assertEquals('handleCondition should be called last.', 4, testObj.steps); -} - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/deferredtestcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/deferredtestcase.js.svn-base deleted file mode 100644 index 3d28b55..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/deferredtestcase.js.svn-base +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Defines DeferredTestCase class. By calling waitForDeferred(), - * tests in DeferredTestCase can wait for a Deferred object to complete its - * callbacks before continuing to the next test. - * - * Example Usage: - * - * var deferredTestCase = goog.testing.DeferredTestCase.createAndInstall(); - * // Optionally, set a longer-than-usual step timeout. - * deferredTestCase.stepTimeout = 15 * 1000; // 15 seconds - * - * function testDeferredCallbacks() { - * var callbackTime = goog.now(); - * var callbacks = new goog.async.Deferred(); - * deferredTestCase.addWaitForAsync('Waiting for 1st callback', callbacks); - * callbacks.addCallback( - * function() { - * assertTrue( - * 'We\'re going back in time!', goog.now() >= callbackTime); - * callbackTime = goog.now(); - * }); - * deferredTestCase.addWaitForAsync('Waiting for 2nd callback', callbacks); - * callbacks.addCallback( - * function() { - * assertTrue( - * 'We\'re going back in time!', goog.now() >= callbackTime); - * callbackTime = goog.now(); - * }); - * deferredTestCase.addWaitForAsync('Waiting for last callback', callbacks); - * callbacks.addCallback( - * function() { - * assertTrue( - * 'We\'re going back in time!', goog.now() >= callbackTime); - * callbackTime = goog.now(); - * }); - * - * deferredTestCase.waitForDeferred(callbacks); - * } - * - * Note that DeferredTestCase still preserves the functionality of - * AsyncTestCase. - * - * @see.goog.async.Deferred - * @see goog.testing.AsyncTestCase - */ - -goog.provide('goog.testing.DeferredTestCase'); - -goog.require('goog.async.Deferred'); -goog.require('goog.testing.AsyncTestCase'); -goog.require('goog.testing.TestCase'); - - - -/** - * A test case that can asynchronously wait on a Deferred object. - * @param {string=} opt_name A descriptive name for the test case. - * @constructor - * @extends {goog.testing.AsyncTestCase} - */ -goog.testing.DeferredTestCase = function(opt_name) { - goog.testing.AsyncTestCase.call(this, opt_name); -}; -goog.inherits(goog.testing.DeferredTestCase, goog.testing.AsyncTestCase); - - -/** - * Preferred way of creating a DeferredTestCase. Creates one and initializes it - * with the G_testRunner. - * @param {string=} opt_name A descriptive name for the test case. - * @return {goog.testing.DeferredTestCase} The created DeferredTestCase. - */ -goog.testing.DeferredTestCase.createAndInstall = function(opt_name) { - var deferredTestCase = new goog.testing.DeferredTestCase(opt_name); - goog.testing.TestCase.initializeTestRunner(deferredTestCase); - return deferredTestCase; -}; - - -/** - * Handler for when the test produces an error. - * @param {Error|string} err The error object. - * @protected - * @throws Always throws a ControlBreakingException. - */ -goog.testing.DeferredTestCase.prototype.onError = function(err) { - this.doAsyncError(err); -}; - - -/** - * Handler for when the test succeeds. - * @protected - */ -goog.testing.DeferredTestCase.prototype.onSuccess = function() { - this.continueTesting(); -}; - - -/** - * Adds a callback to update the wait message of this async test case. Using - * this method generously also helps to document the test flow. - * @param {string} msg The update wait status message. - * @param {goog.async.Deferred} d The deferred object to add the waitForAsync - * callback to. - * @see goog.testing.AsyncTestCase#waitForAsync - */ -goog.testing.DeferredTestCase.prototype.addWaitForAsync = function(msg, d) { - d.addCallback(goog.bind(this.waitForAsync, this, msg)); -}; - - -/** - * Wires up given Deferred object to the test case, then starts the - * goog.async.Deferred object's callback. - * @param {!string|goog.async.Deferred} a The wait status message or the - * deferred object to wait for. - * @param {goog.async.Deferred=} opt_b The deferred object to wait for. - */ -goog.testing.DeferredTestCase.prototype.waitForDeferred = function(a, opt_b) { - var waitMsg; - var deferred; - switch (arguments.length) { - case 1: - deferred = a; - waitMsg = null; - break; - case 2: - deferred = opt_b; - waitMsg = a; - break; - default: // Shouldn't be here in compiled mode - throw Error('Invalid number of arguments'); - } - - deferred.addCallbacks(this.onSuccess, this.onError, this); - if (!waitMsg) { - waitMsg = - 'Waiting for deferred in ' + this.activeTest.name; - } - this.waitForAsync( /** @type {!string} */ (waitMsg)); - deferred.callback(true); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/deferredtestcase_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/deferredtestcase_test.html.svn-base deleted file mode 100644 index 09d1910..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/deferredtestcase_test.html.svn-base +++ /dev/null @@ -1,151 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2010 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- ---> -<head> -<title>Closure Unit Tests - goog.testing.DeferredTestCase Asyncronous Tests</title> - <script src="../base.js"></script> - <script> - goog.require('goog.async.Deferred'); - goog.require('goog.testing.DeferredTestCase'); - goog.require('goog.testing.TestRunner'); - goog.require('goog.testing.jsunit'); - </script> -</head> -<body> - <script type="text/javascript"> - var deferredTestCase = - goog.testing.DeferredTestCase.createAndInstall(document.title); - var testTestCase; - var runner; - - // Optionally, set a longer-than-usual step timeout. - deferredTestCase.stepTimeout = 15 * 1000; // 15 seconds - - // This is the sample code in deferredtestcase.js - function testDeferredCallbacks() { - var callbackTime = goog.now(); - var callbacks = new goog.async.Deferred(); - deferredTestCase.addWaitForAsync('Waiting for 1st callback', callbacks); - callbacks.addCallback( - function() { - assertTrue( - 'We\'re going back in time!', goog.now() >= callbackTime); - callbackTime = goog.now(); - }); - deferredTestCase.addWaitForAsync('Waiting for 2nd callback', callbacks); - callbacks.addCallback( - function() { - assertTrue( - 'We\'re going back in time!', goog.now() >= callbackTime); - callbackTime = goog.now(); - }); - deferredTestCase.addWaitForAsync('Waiting for last callback', callbacks); - callbacks.addCallback( - function() { - assertTrue( - 'We\'re going back in time!', goog.now() >= callbackTime); - callbackTime = goog.now(); - }); - - deferredTestCase.waitForDeferred(callbacks); - } - - function createDeferredTestCase(d) { - testTestCase = new goog.testing.DeferredTestCase('Foobar TestCase'); - testTestCase.add(new goog.testing.TestCase.Test( - 'Foobar Test', - function() { - this.waitForDeferred(d); - }, - testTestCase)); - - var testCompleteCallback = new goog.async.Deferred(); - testTestCase.setCompletedCallback( - function() { - testCompleteCallback.callback(true); - }); - - // We're not going to use the runner to run the test, but we attach one - // here anyway because without a runner TestCase throws an exception in - // finalize(). - var runner = new goog.testing.TestRunner(); - runner.initialize(testTestCase); - - return testCompleteCallback; - } - - function testDeferredWait() { - var d = new goog.async.Deferred(); - deferredTestCase.addWaitForAsync('Foobar', d); - d.addCallback(function() { - return goog.async.Deferred.succeed(true); - }); - deferredTestCase.waitForDeferred(d); - } - - function testNonAsync() { - assertTrue(true); - } - - function testPassWithTestRunner() { - var d = new goog.async.Deferred(); - d.addCallback(function() { - return goog.async.Deferred.succeed(true); - //return goog.async.Deferred.fail(true); - //return new goog.async.Deferred(); - }); - - var testCompleteDeferred = createDeferredTestCase(d); - testTestCase.execute(); - - var deferredCallbackOnPass = new goog.async.Deferred(); - deferredCallbackOnPass.addCallback(function() { - return testCompleteDeferred; - }); - deferredCallbackOnPass.addCallback(function() { - assertTrue('Test case should have succeded.', testTestCase.isSuccess()); - }); - - deferredTestCase.waitForDeferred(deferredCallbackOnPass); - } - - function testFailWithTestRunner() { - var d = new goog.async.Deferred(); - d.addCallback(function() { - return goog.async.Deferred.fail(true); - }); - - var testCompleteDeferred = createDeferredTestCase(d); - - // Override and consume test exception - var origFn = testTestCase.doAsyncError; - testTestCase.doAsyncError = function() { - try { - origFn(); - } catch (e) { - testCompleteDeferred.callback(true); - } - } - testTestCase.execute(); - - var deferredCallbackOnFail = new goog.async.Deferred(); - deferredCallbackOnFail.addCallback(function() { - return testCompleteDeferred; - }); - deferredCallbackOnFail.addCallback(function() { - assertTrue('Test case should have failed.', !testTestCase.isSuccess()); - }); - - deferredTestCase.waitForDeferred(deferredCallbackOnFail); - } - - </script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/dom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/dom.js.svn-base deleted file mode 100644 index 4056c19..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/dom.js.svn-base +++ /dev/null @@ -1,606 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Testing utilities for DOM related tests. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.testing.dom'); - -goog.require('goog.dom'); -goog.require('goog.dom.NodeIterator'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.TagIterator'); -goog.require('goog.dom.TagName'); -goog.require('goog.dom.classes'); -goog.require('goog.iter'); -goog.require('goog.object'); -goog.require('goog.string'); -goog.require('goog.style'); -goog.require('goog.testing.asserts'); -goog.require('goog.userAgent'); - - -/** - * A unique object to use as an end tag marker. - * @type {Object} - * @private - */ -goog.testing.dom.END_TAG_MARKER_ = {}; - - -/** - * Tests if the given iterator over nodes matches the given Array of node - * descriptors. Throws an error if any match fails. - * @param {goog.iter.Iterator} it An iterator over nodes. - * @param {Array.<Node|number|string>} array Array of node descriptors to match - * against. Node descriptors can be any of the following: - * Node: Test if the two nodes are equal. - * number: Test node.nodeType == number. - * string starting with '#': Match the node's id with the text - * after "#". - * other string: Match the text node's contents. - */ -goog.testing.dom.assertNodesMatch = function(it, array) { - var i = 0; - goog.iter.forEach(it, function(node) { - if (array.length <= i) { - fail('Got more nodes than expected: ' + goog.testing.dom.describeNode_( - node)); - } - var expected = array[i]; - - if (goog.dom.isNodeLike(expected)) { - assertEquals('Nodes should match at position ' + i, expected, node); - } else if (goog.isNumber(expected)) { - assertEquals('Node types should match at position ' + i, expected, - node.nodeType); - } else if (expected.charAt(0) == '#') { - assertEquals('Expected element at position ' + i, - goog.dom.NodeType.ELEMENT, node.nodeType); - var expectedId = expected.substr(1); - assertEquals('IDs should match at position ' + i, - expectedId, node.id); - - } else { - assertEquals('Expected text node at position ' + i, - goog.dom.NodeType.TEXT, node.nodeType); - assertEquals('Node contents should match at position ' + i, - expected, node.nodeValue); - } - - i++; - }); - - assertEquals('Used entire match array', array.length, i); -}; - - -/** - * Exposes a node as a string. - * @param {Node} node A node. - * @return {string} A string representation of the node. - */ -goog.testing.dom.exposeNode = function(node) { - return (node.tagName || node.nodeValue) + (node.id ? '#' + node.id : '') + - ':"' + (node.innerHTML || '') + '"'; -}; - - -/** - * Exposes the nodes of a range wrapper as a string. - * @param {goog.dom.AbstractRange} range A range. - * @return {string} A string representation of the range. - */ -goog.testing.dom.exposeRange = function(range) { - // This is deliberately not implemented as - // goog.dom.AbstractRange.prototype.toString, because it is non-authoritative. - // Two equivalent ranges may have very different exposeRange values, and - // two different ranges may have equal exposeRange values. - // (The mapping of ranges to DOM nodes/offsets is a many-to-many mapping). - if (!range) { - return 'null'; - } - return goog.testing.dom.exposeNode(range.getStartNode()) + ':' + - range.getStartOffset() + ' to ' + - goog.testing.dom.exposeNode(range.getEndNode()) + ':' + - range.getEndOffset(); -}; - - -/** - * Determines if the current user agent matches the specified string. Returns - * false if the string does specify at least one user agent but does not match - * the running agent. - * @param {string} userAgents Space delimited string of user agents. - * @return {boolean} Whether the user agent was matched. Also true if no user - * agent was listed in the expectation string. - * @private - */ -goog.testing.dom.checkUserAgents_ = function(userAgents) { - if (goog.string.startsWith(userAgents, '!')) { - if (goog.string.contains(userAgents, ' ')) { - throw new Error('Only a single negative user agent may be specified'); - } - return !goog.userAgent[userAgents.substr(1)]; - } - - var agents = userAgents.split(' '); - var hasUserAgent = false; - for (var i = 0, len = agents.length; i < len; i++) { - var cls = agents[i]; - if (cls in goog.userAgent) { - hasUserAgent = true; - if (goog.userAgent[cls]) { - return true; - } - } - } - // If we got here, there was a user agent listed but we didn't match it. - return !hasUserAgent; -}; - - -/** - * Map function that converts end tags to a specific object. - * @param {Node} node The node to map. - * @param {Object} ignore Always undefined. - * @param {goog.dom.TagIterator} iterator The iterator. - * @return {Node|Object} The resulting iteration item. - * @private - */ -goog.testing.dom.endTagMap_ = function(node, ignore, iterator) { - return iterator.isEndTag() ? goog.testing.dom.END_TAG_MARKER_ : node; -}; - - -/** - * Check if the given node is important. A node is important if it is a - * non-empty text node, a non-annotated element, or an element annotated to - * match on this user agent. - * @param {Node} node The node to test. - * @return {boolean} Whether this node should be included for iteration. - * @private - */ -goog.testing.dom.nodeFilter_ = function(node) { - if (node.nodeType == goog.dom.NodeType.TEXT) { - // If a node is part of a string of text nodes and it has spaces in it, - // we allow it since it's going to affect the merging of nodes done below. - if (goog.string.isBreakingWhitespace(node.nodeValue) && - (!node.previousSibling || - node.previousSibling.nodeType != goog.dom.NodeType.TEXT) && - (!node.nextSibling || - node.nextSibling.nodeType != goog.dom.NodeType.TEXT)) { - return false; - } - // Allow optional text to be specified as [[BROWSER1 BROWSER2]]Text - var match = node.nodeValue.match(/^\[\[(.+)\]\]/); - if (match) { - return goog.testing.dom.checkUserAgents_(match[1]); - } - } else if (node.className) { - return goog.testing.dom.checkUserAgents_(node.className); - } - return true; -}; - - -/** - * Determines the text to match from the given node, removing browser - * specification strings. - * @param {Node} node The node expected to match. - * @return {string} The text, stripped of browser specification strings. - * @private - */ -goog.testing.dom.getExpectedText_ = function(node) { - // Strip off the browser specifications. - return node.nodeValue.match(/^(\[\[.+\]\])?(.*)/)[2]; -}; - - -/** - * Describes the given node. - * @param {Node} node The node to describe. - * @return {string} A description of the node. - * @private - */ -goog.testing.dom.describeNode_ = function(node) { - if (node.nodeType == goog.dom.NodeType.TEXT) { - return '[Text: ' + node.nodeValue + ']'; - } else { - return '<' + node.tagName + (node.id ? ' #' + node.id : '') + ' .../>'; - } -}; - - -/** - * Assert that the html in {@code actual} is substantially similar to - * htmlPattern. This method tests for the same set of styles, for the same - * order of nodes, and the presence of attributes. Breaking whitespace nodes - * are ignored. Elements can be - * annotated with classnames corresponding to keys in goog.userAgent and will be - * expected to show up in that user agent and expected not to show up in - * others. - * @param {string} htmlPattern The pattern to match. - * @param {!Element} actual The element to check: its contents are matched - * against the HTML pattern. - * @param {boolean=} opt_strictAttributes If false, attributes that appear in - * htmlPattern must be in actual, but actual can have attributes not - * present in htmlPattern. If true, htmlPattern and actual must have the - * same set of attributes. Default is false. - */ -goog.testing.dom.assertHtmlContentsMatch = function(htmlPattern, actual, - opt_strictAttributes) { - var div = goog.dom.createDom(goog.dom.TagName.DIV); - div.innerHTML = htmlPattern; - - var errorSuffix = '\nExpected\n' + htmlPattern + '\nActual\n' + - actual.innerHTML; - - var actualIt = goog.iter.filter( - goog.iter.map(new goog.dom.TagIterator(actual), - goog.testing.dom.endTagMap_), - goog.testing.dom.nodeFilter_); - - var expectedIt = goog.iter.filter(new goog.dom.NodeIterator(div), - goog.testing.dom.nodeFilter_); - - var actualNode; - var preIterated = false; - var advanceActualNode = function() { - // If the iterator has already been advanced, don't advance it again. - if (!preIterated) { - actualNode = /** @type {Node} */ (goog.iter.nextOrValue(actualIt, null)); - } - preIterated = false; - - // Advance the iterator so long as it is return end tags. - while (actualNode == goog.testing.dom.END_TAG_MARKER_) { - actualNode = /** @type {Node} */ (goog.iter.nextOrValue(actualIt, null)); - } - }; - - // HACK(user): IE has unique ideas about whitespace handling when setting - // innerHTML. This results in elision of leading whitespace in the expected - // nodes where doing so doesn't affect visible rendering. As a workaround, we - // remove the leading whitespace in the actual nodes where necessary. - // - // The collapsible variable tracks whether we should collapse the whitespace - // in the next Text node we encounter. - var IE_TEXT_COLLAPSE = goog.userAgent.IE && !goog.userAgent.isVersion('9'); - var collapsible = true; - - var number = 0; - goog.iter.forEach(expectedIt, function(expectedNode) { - expectedNode = /** @type {Node} */ (expectedNode); - - advanceActualNode(); - assertNotNull('Finished actual HTML before finishing expected HTML at ' + - 'node number ' + number + ': ' + - goog.testing.dom.describeNode_(expectedNode) + errorSuffix, - actualNode); - - // Do no processing for expectedNode == div. - if (expectedNode == div) { - return; - } - - assertEquals('Should have the same node type, got ' + - goog.testing.dom.describeNode_(actualNode) + ' but expected ' + - goog.testing.dom.describeNode_(expectedNode) + '.' + errorSuffix, - expectedNode.nodeType, actualNode.nodeType); - - if (expectedNode.nodeType == goog.dom.NodeType.ELEMENT) { - assertEquals('Tag names should match' + errorSuffix, - expectedNode.tagName, actualNode.tagName); - assertObjectEquals('Should have same styles' + errorSuffix, - goog.style.parseStyleAttribute(expectedNode.style.cssText), - goog.style.parseStyleAttribute(actualNode.style.cssText)); - goog.testing.dom.assertAttributesEqual_(errorSuffix, expectedNode, - actualNode, !!opt_strictAttributes); - - if (IE_TEXT_COLLAPSE && - goog.style.getCascadedStyle( - /** @type {Element} */ (actualNode), 'display') != 'inline') { - // Text may be collapsed after any non-inline element. - collapsible = true; - } - } else { - // Concatenate text nodes until we reach a non text node. - var actualText = actualNode.nodeValue; - preIterated = true; - while ((actualNode = /** @type {Node} */ - (goog.iter.nextOrValue(actualIt, null))) && - actualNode.nodeType == goog.dom.NodeType.TEXT) { - actualText += actualNode.nodeValue; - } - - if (IE_TEXT_COLLAPSE) { - // Collapse the leading whitespace, unless the string consists entirely - // of whitespace. - if (collapsible && !goog.string.isEmpty(actualText)) { - actualText = goog.string.trimLeft(actualText); - } - // Prepare to collapse whitespace in the next Text node if this one does - // not end in a whitespace character. - collapsible = /\s$/.test(actualText); - } - - var expectedText = goog.testing.dom.getExpectedText_(expectedNode); - if ((actualText && !goog.string.isBreakingWhitespace(actualText)) || - (expectedText && !goog.string.isBreakingWhitespace(expectedText))) { - var normalizedActual = actualText.replace(/\s+/g, ' '); - var normalizedExpected = expectedText.replace(/\s+/g, ' '); - - assertEquals('Text should match' + errorSuffix, normalizedExpected, - normalizedActual); - } - } - - number++; - }); - - advanceActualNode(); - assertNull('Finished expected HTML before finishing actual HTML' + - errorSuffix, goog.iter.nextOrValue(actualIt, null)); -}; - - -/** - * Assert that the html in {@code actual} is substantially similar to - * htmlPattern. This method tests for the same set of styles, and for the same - * order of nodes. Breaking whitespace nodes are ignored. Elements can be - * annotated with classnames corresponding to keys in goog.userAgent and will be - * expected to show up in that user agent and expected not to show up in - * others. - * @param {string} htmlPattern The pattern to match. - * @param {string} actual The html to check. - */ -goog.testing.dom.assertHtmlMatches = function(htmlPattern, actual) { - var div = goog.dom.createDom(goog.dom.TagName.DIV); - div.innerHTML = actual; - - goog.testing.dom.assertHtmlContentsMatch(htmlPattern, div); -}; - - -/** - * Finds the first text node descendant of root with the given content. Note - * that this operates on a text node level, so if text nodes get split this - * may not match the user visible text. Using normalize() may help here. - * @param {string|RegExp} textOrRegexp The text to find, or a regular - * expression to find a match of. - * @param {Element} root The element to search in. - * @return {Node} The first text node that matches, or null if none is found. - */ -goog.testing.dom.findTextNode = function(textOrRegexp, root) { - var it = new goog.dom.NodeIterator(root); - var ret = goog.iter.nextOrValue(goog.iter.filter(it, function(node) { - if (node.nodeType == goog.dom.NodeType.TEXT) { - if (goog.isString(textOrRegexp)) { - return node.nodeValue == textOrRegexp; - } else { - return !!node.nodeValue.match(textOrRegexp); - } - } else { - return false; - } - }), null); - return /** @type {Node} */ (ret); -}; - - -/** - * Assert the end points of a range. - * - * Notice that "Are two ranges visually identical?" and "Do two ranges have - * the same endpoint?" are independent questions. Two visually identical ranges - * may have different endpoints. And two ranges with the same endpoints may - * be visually different. - * - * @param {Node} start The expected start node. - * @param {number} startOffset The expected start offset. - * @param {Node} end The expected end node. - * @param {number} endOffset The expected end offset. - * @param {goog.dom.AbstractRange} range The actual range. - */ -goog.testing.dom.assertRangeEquals = function(start, startOffset, end, - endOffset, range) { - assertEquals('Unexpected start node', start, range.getStartNode()); - assertEquals('Unexpected end node', end, range.getEndNode()); - assertEquals('Unexpected start offset', startOffset, range.getStartOffset()); - assertEquals('Unexpected end offset', endOffset, range.getEndOffset()); -}; - - -/** - * Gets the value of a DOM attribute in deterministic way. - * @param {!Node} node A node. - * @param {string} name Attribute name. - * @return {*} Attribute value. - * @private - */ -goog.testing.dom.getAttributeValue_ = function(node, name) { - // These hacks avoid nondetermistic results in the following cases: - // IE7: document.createElement('input').height returns a random number. - // FF3: getAttribute('disabled') returns different value for <div disabled=""> - // and <div disabled="disabled"> - // WebKit: Two radio buttons with the same name can't be checked at the same - // time, even if only one of them is in the document. - if (goog.userAgent.WEBKIT && node.tagName == 'INPUT' && - node['type'] == 'radio' && name == 'checked') { - return false; - } - return goog.isDef(node[name]) && - typeof node.getAttribute(name) != typeof node[name] ? - node[name] : node.getAttribute(name); -}; - - -/** - * Assert that the attributes of two Nodes are the same (ignoring any - * instances of the style attribute). - * @param {string} errorSuffix String to add to end of error messages. - * @param {Node} expectedNode The node whose attributes we are expecting. - * @param {Node} actualNode The node with the actual attributes. - * @param {boolean} strictAttributes If false, attributes that appear in - * expectedNode must also be in actualNode, but actualNode can have - * attributes not present in expectedNode. If true, expectedNode and - * actualNode must have the same set of attributes. - * @private - */ -goog.testing.dom.assertAttributesEqual_ = function(errorSuffix, - expectedNode, actualNode, strictAttributes) { - if (strictAttributes) { - goog.testing.dom.compareClassAttribute_(expectedNode, actualNode); - } - - var expectedAttributes = expectedNode.attributes; - var actualAttributes = actualNode.attributes; - - for (var i = 0, len = expectedAttributes.length; i < len; i++) { - var expectedName = expectedAttributes[i].name; - var expectedValue = goog.testing.dom.getAttributeValue_(expectedNode, - expectedName); - - var actualAttribute = actualAttributes[expectedName]; - var actualValue = goog.testing.dom.getAttributeValue_(actualNode, - expectedName); - - // IE enumerates attribute names in the expected node that are not present, - // causing an undefined actualAttribute. - if (!expectedValue && !actualValue) { - continue; - } - - if (expectedName == 'id' && goog.userAgent.IE) { - goog.testing.dom.compareIdAttributeForIe_( - /** @type {string} */ (expectedValue), actualAttribute, - strictAttributes, errorSuffix); - continue; - } - - if (goog.testing.dom.ignoreAttribute_(expectedName)) { - continue; - } - - assertNotUndefined('Expected to find attribute with name ' + - expectedName + ', in element ' + - goog.testing.dom.describeNode_(actualNode) + errorSuffix, - actualAttribute); - assertEquals('Expected attribute ' + expectedName + - ' has a different value ' + errorSuffix, - expectedValue, - goog.testing.dom.getAttributeValue_(actualNode, actualAttribute.name)); - } - - if (strictAttributes) { - for (i = 0; i < actualAttributes.length; i++) { - var actualName = actualAttributes[i].name; - var actualAttribute = actualAttributes.getNamedItem(actualName); - - if (!actualAttribute || goog.testing.dom.ignoreAttribute_(actualName)) { - continue; - } - - assertNotUndefined('Unexpected attribute with name ' + - actualName + ' in element ' + - goog.testing.dom.describeNode_(actualNode) + errorSuffix, - expectedAttributes[actualName]); - } - } -}; - - -/** - * Assert the class attribute of actualNode is the same as the one in - * expectedNode, ignoring classes that are useragents. - * @param {Node} expectedNode The DOM node whose class we expect. - * @param {Node} actualNode The DOM node with the actual class. - * @private - */ -goog.testing.dom.compareClassAttribute_ = function(expectedNode, - actualNode) { - var classes = goog.dom.classes.get(expectedNode); - - var expectedClasses = []; - for (var i = 0, len = classes.length; i < len; i++) { - if (!(classes[i] in goog.userAgent)) { - expectedClasses.push(classes[i]); - } - } - expectedClasses.sort(); - - var actualClasses = goog.dom.classes.get(actualNode); - actualClasses.sort(); - - assertArrayEquals( - 'Expected class was: ' + expectedClasses.join(' ') + - ', but actual class was: ' + actualNode.className, - expectedClasses, actualClasses); -}; - - -/** - * Set of attributes IE adds to elements randomly. - * @type {Object} - * @private - */ -goog.testing.dom.BAD_IE_ATTRIBUTES_ = goog.object.createSet( - 'methods', 'CHECKED', 'dataFld', 'dataFormatAs', 'dataSrc'); - - -/** - * Whether to ignore the attribute. - * @param {string} name Name of the attribute. - * @return {boolean} True if the attribute should be ignored. - * @private - */ -goog.testing.dom.ignoreAttribute_ = function(name) { - if (name == 'style' || name == 'class') { - return true; - } - return goog.userAgent.IE && goog.testing.dom.BAD_IE_ATTRIBUTES_[name]; -}; - - -/** - * Compare id attributes for IE. In IE, if an element lacks an id attribute - * in the original HTML, the element object will still have such an attribute, - * but its value will be the empty string. - * @param {string} expectedValue The expected value of the id attribute. - * @param {Attr} actualAttribute The actual id attribute. - * @param {boolean} strictAttributes Whether strict attribute checking should be - * done. - * @param {string} errorSuffix String to append to error messages. - * @private - */ -goog.testing.dom.compareIdAttributeForIe_ = function(expectedValue, - actualAttribute, strictAttributes, errorSuffix) { - if (expectedValue === '') { - if (strictAttributes) { - assertTrue('Unexpected attribute with name id in element ' + - errorSuffix, actualAttribute.value == ''); - } - } else { - assertNotUndefined('Expected to find attribute with name id, in element ' + - errorSuffix, actualAttribute); - assertNotEquals('Expected to find attribute with name id, in element ' + - errorSuffix, '', actualAttribute.value); - assertEquals('Expected attribute has a different value ' + errorSuffix, - expectedValue, actualAttribute.value); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/dom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/dom_test.html.svn-base deleted file mode 100644 index 0d595fe..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/dom_test.html.svn-base +++ /dev/null @@ -1,438 +0,0 @@ -<!DOCTYPE html> -<html lang="en" dir="ltr"> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<!-- -This test has not yet been updated to run on IE8. See http://b/hotlist?id=36311 ---> -<!--meta http-equiv="X-UA-Compatible" content="IE=edge"--> -<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"> - <title>Closure Unit Tests - goog.testing.dom</title> - <script src="../base.js"></script> - <script> - goog.require('goog.dom'); - goog.require('goog.dom.TagName'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); - </script> -</head> -<body> -<div id="root"></div> -<script type="text/javascript"> - var root = goog.dom.getElement('root'); - - function setUp() { - root.innerHTML = ''; - } - - function testFindNode() { - // Test the easiest case. - root.innerHTML = 'a<br>b'; - assertEquals(goog.testing.dom.findTextNode('a', root), root.firstChild); - assertEquals(goog.testing.dom.findTextNode('b', root), root.lastChild); - assertNull(goog.testing.dom.findTextNode('c', root)); - } - - function testFindNodeDuplicate() { - // Test duplicate. - root.innerHTML = 'c<br>c'; - assertEquals('Should return first duplicate', - goog.testing.dom.findTextNode('c', root), root.firstChild); - } - - function findNodeWithHierarchy() { - // Test a more complicated hierarchy. - root.innerHTML = '<div>a<p>b<span>c</span>d</p>e</div>'; - assertEquals(goog.dom.TagName.DIV, - goog.testing.dom.findTextNode('a', root).parentNode.tagName); - assertEquals(goog.dom.TagName.P, - goog.testing.dom.findTextNode('b', root).parentNode.tagName); - assertEquals(goog.dom.TagName.SPAN, - goog.testing.dom.findTextNode('c', root).parentNode.tagName); - assertEquals(goog.dom.TagName.P, - goog.testing.dom.findTextNode('d', root).parentNode.tagName); - assertEquals(goog.dom.TagName.DIV, - goog.testing.dom.findTextNode('e', root).parentNode.tagName); - } - - function setUpAssertHtmlMatches() { - var tag1, tag2; - if (goog.userAgent.IE) { - tag1 = goog.dom.TagName.DIV; - } else if (goog.userAgent.WEBKIT) { - tag1 = goog.dom.TagName.P; - tag2 = goog.dom.TagName.BR; - } else if (goog.userAgent.GECKO) { - tag1 = goog.dom.TagName.SPAN; - tag2 = goog.dom.TagName.BR; - } - - var parent = goog.dom.createDom(goog.dom.TagName.DIV); - root.appendChild(parent); - parent.style.fontSize = '2em'; - parent.style.display = 'none'; - if (!goog.userAgent.WEBKIT) { - parent.appendChild(goog.dom.createTextNode('NonWebKitText')); - } - - if (tag1) { - var e1 = goog.dom.createDom(tag1); - parent.appendChild(e1); - parent = e1; - } - if (tag2) { - parent.appendChild(goog.dom.createDom(tag2)); - } - parent.appendChild(goog.dom.createTextNode('Text')); - if (goog.userAgent.WEBKIT) { - root.firstChild.appendChild(goog.dom.createTextNode('WebKitText')); - } - } - - function testAssertHtmlContentsMatch() { - setUpAssertHtmlMatches(); - - goog.testing.dom.assertHtmlContentsMatch( - '<div style="display: none; font-size: 2em">' + - '[[!WEBKIT]]NonWebKitText<div class="IE"><p class="WEBKIT">' + - '<span class="GECKO"><br class="GECKO WEBKIT">Text</span></p></div>' + - '</div>[[WEBKIT]]WebKitText', - root); - } - - function testAssertHtmlMismatchText() { - setUpAssertHtmlMatches(); - - var e = assertThrows('Should fail due to mismatched text', function() { - goog.testing.dom.assertHtmlContentsMatch( - '<div style="display: none; font-size: 2em">' + - '[[IE GECKO]]NonWebKitText<div class="IE"><p class="WEBKIT">' + - '<span class="GECKO"><br class="GECKO WEBKIT">Bad</span></p></div>' + - '</div>[[WEBKIT]]Extra', - root); - }); - assertContains('Text should match', e.message); - } - - function testAssertHtmlMismatchTag() { - setUpAssertHtmlMatches(); - - var e = assertThrows('Should fail due to mismatched tag', function() { - goog.testing.dom.assertHtmlContentsMatch( - '<span style="display: none; font-size: 2em">' + - '[[IE GECKO]]NonWebKitText<div class="IE"><p class="WEBKIT">' + - '<span class="GECKO"><br class="GECKO WEBKIT">Text</span></p></div>' + - '</span>[[WEBKIT]]Extra', - root); - }); - assertContains('Tag names should match', e.message); - } - - function testAssertHtmlMismatchStyle() { - setUpAssertHtmlMatches(); - - var e = assertThrows('Should fail due to mismatched style', function() { - goog.testing.dom.assertHtmlContentsMatch( - '<div style="display: none; font-size: 3em">' + - '[[IE GECKO]]NonWebKitText<div class="IE"><p class="WEBKIT">' + - '<span class="GECKO"><br class="GECKO WEBKIT">Text</span></p></div>' + - '</div>[[WEBKIT]]Extra', - root); - }); - assertContains('Should have same styles', e.message); - } - - function testAssertHtmlMismatchOptionalText() { - setUpAssertHtmlMatches(); - - var e = assertThrows('Should fail due to mismatched text', function() { - goog.testing.dom.assertHtmlContentsMatch( - '<div style="display: none; font-size: 2em">' + - '[[IE GECKO]]Bad<div class="IE"><p class="WEBKIT">' + - '<span class="GECKO"><br class="GECKO WEBKIT">Text</span></p></div>' + - '</div>[[WEBKIT]]Bad', - root); - }); - assertContains('Text should match', e.message); - } - - function testAssertHtmlMismatchExtraActualAfterText() { - root.innerHTML = '<div>abc</div>def'; - - var e = assertThrows('Should fail due to extra actual nodes', function() { - goog.testing.dom.assertHtmlContentsMatch('<div>abc</div>', root); - }); - assertContains('Finished expected HTML before', e.message); - } - - function testAssertHtmlMismatchExtraActualAfterElement() { - root.innerHTML = '<br>def'; - - var e = assertThrows('Should fail due to extra actual nodes', function() { - goog.testing.dom.assertHtmlContentsMatch('<br>', root); - }); - assertContains('Finished expected HTML before', e.message); - } - - function testAssertHtmlMatchesWithSplitTextNodes() { - root.appendChild(goog.dom.createTextNode('1')); - root.appendChild(goog.dom.createTextNode('2')); - root.appendChild(goog.dom.createTextNode('3')); - goog.testing.dom.assertHtmlContentsMatch('123', root); - } - - function testAssertHtmlMatchesWithDifferentlyOrderedAttributes() { - root.innerHTML = '<div foo="a" bar="b" class="className"></div>'; - - goog.testing.dom.assertHtmlContentsMatch( - '<div bar="b" class="className" foo="a"></div>', root, true); - } - - function testAssertHtmlMismatchWithDifferentNumberOfAttributes() { - root.innerHTML = '<div foo="a" bar="b"></div>'; - - var e = assertThrows(function() { - goog.testing.dom.assertHtmlContentsMatch( - '<div foo="a"></div>', root, true); - }); - assertContains('Unexpected attribute with name bar in element', e.message); - } - - function testAssertHtmlMismatchWithDifferentAttributeNames() { - root.innerHTML = '<div foo="a" bar="b"></div>'; - - var e = assertThrows(function() { - goog.testing.dom.assertHtmlContentsMatch( - '<div foo="a" baz="b"></div>', root, true); - }); - assertContains('Expected to find attribute with name baz', e.message); - } - - function testAssertHtmlMismatchWithDifferentClassNames() { - root.innerHTML = '<div class="className1"></div>'; - - var e = assertThrows(function() { - goog.testing.dom.assertHtmlContentsMatch( - '<div class="className2"></div>', root, true); - }); - assertContains( - 'Expected class was: className2, but actual class was: className1', - e.message); - } - - function testAssertHtmlMatchesWithClassNameAndUserAgentSpecified() { - root.innerHTML = - '<div>' + (goog.userAgent.GECKO ? '<div class="foo"></div>' : '') + - '</div>'; - - goog.testing.dom.assertHtmlContentsMatch( - '<div><div class="foo GECKO"></div></div>', - root, true); - } - - function testAssertHtmlMatchesWithClassesInDifferentOrder() { - root.innerHTML = '<div class="class1 class2"></div>'; - - goog.testing.dom.assertHtmlContentsMatch( - '<div class="class2 class1"></div>', root, true); - } - - function testAssertHtmlMismatchWithDifferentAttributeValues() { - root.innerHTML = '<div foo="b" bar="a"></div>'; - - var e = assertThrows(function() { - goog.testing.dom.assertHtmlContentsMatch( - '<div foo="a" bar="a"></div>', root, true); - }); - assertContains('Expected attribute foo has a different value', e.message); - } - - function testAssertHtmlMatchesWhenStrictAttributesIsFalse() { - root.innerHTML = '<div foo="a" bar="b"></div>'; - - goog.testing.dom.assertHtmlContentsMatch('<div foo="a"></div>', root); - } - - function testAssertHtmlMatchesForMethodsAttribute() { - root.innerHTML = '<a methods="get"></a>'; - - goog.testing.dom.assertHtmlContentsMatch('<a></a>', root); - goog.testing.dom.assertHtmlContentsMatch('<a methods="get"></a>', root); - goog.testing.dom.assertHtmlContentsMatch('<a methods="get"></a>', root, - true); - } - - function testAssertHtmlMatchesForMethodsAttribute() { - root.innerHTML = '<input></input>'; - - goog.testing.dom.assertHtmlContentsMatch('<input></input>', root); - goog.testing.dom.assertHtmlContentsMatch('<input></input>', root, true); - } - - function testAssertHtmlMatchesForIdAttribute() { - root.innerHTML = '<div id="foo"></div>'; - - goog.testing.dom.assertHtmlContentsMatch('<div></div>', root); - goog.testing.dom.assertHtmlContentsMatch('<div id="foo"></div>', root); - goog.testing.dom.assertHtmlContentsMatch('<div id="foo"></div>', root, - true); - } - - function testAssertHtmlMatchesWhenIdIsNotSpecified() { - root.innerHTML = '<div id="someId"></div>'; - - goog.testing.dom.assertHtmlContentsMatch('<div></div>', root); - } - - function testAssertHtmlMismatchWhenIdIsNotSpecified() { - root.innerHTML = '<div id="someId"></div>'; - - var e = assertThrows(function() { - goog.testing.dom.assertHtmlContentsMatch('<div></div>', root, true); - }); - assertContains('Unexpected attribute with name id in element', e.message); - } - - function testAssertHtmlMismatchWhenIdIsSpecified() { - root.innerHTML = '<div></div>'; - - var e = assertThrows(function() { - goog.testing.dom.assertHtmlContentsMatch('<div id="someId"></div>', root); - }); - assertContains('Expected to find attribute with name id, in element', - e.message); - - e = assertThrows(function() { - goog.testing.dom.assertHtmlContentsMatch('<div id="someId"></div>', root, - true); - }); - assertContains('Expected to find attribute with name id, in element', - e.message); - } - - function testAssertHtmlMatchesWhenIdIsEmpty() { - root.innerHTML = '<div></div>'; - - goog.testing.dom.assertHtmlContentsMatch('<div></div>', root); - goog.testing.dom.assertHtmlContentsMatch('<div></div>', root, true); - } - - function testAssertHtmlMatchesWithDisabledAttribute() { - var disabledShortest = '<input disabled>'; - var disabledShort = '<input DISABLED="">'; - var disabledLong = '<input disabled="disabled">'; - var enabled = '<input>'; - - root.innerHTML = disabledLong; - goog.testing.dom.assertHtmlContentsMatch(disabledShortest, root, true); - goog.testing.dom.assertHtmlContentsMatch(disabledShort, root, true); - goog.testing.dom.assertHtmlContentsMatch(disabledLong, root, true); - - - var e = assertThrows('Should fail due to mismatched text', function() { - goog.testing.dom.assertHtmlContentsMatch(enabled, root, true); - }); - // Attribute value mismatch in IE. - // Unexpected attribute error in other browsers. - assertContains('disabled', e.message); - } - - function testAssertHtmlMatchesWithCheckedAttribute() { - var checkedShortest = '<input type="radio" name="x" checked>'; - var checkedShort = '<input type="radio" name="x" CHECKED="">'; - var checkedLong = '<input type="radio" name="x" checked="checked">'; - var unchecked = '<input type="radio" name="x">'; - - root.innerHTML = checkedLong; - goog.testing.dom.assertHtmlContentsMatch(checkedShortest, root, true); - goog.testing.dom.assertHtmlContentsMatch(checkedShort, root, true); - goog.testing.dom.assertHtmlContentsMatch(checkedLong, root, true); - if (!goog.userAgent.IE) { - // CHECKED attribute is ignored because it's among BAD_IE_ATTRIBUTES_. - var e = assertThrows('Should fail due to mismatched text', function() { - goog.testing.dom.assertHtmlContentsMatch(unchecked, root, true); - }); - assertContains('Unexpected attribute with name checked', e.message); - } - } - - function testAssertHtmlMatchesWithWhitespace() { - root.innerHTML = ''; - root.appendChild(goog.dom.createTextNode(' A ')); - goog.testing.dom.assertHtmlContentsMatch(' A ', root); - - root.innerHTML = ''; - root.appendChild(goog.dom.createTextNode(' A ')); - root.appendChild(goog.dom.createDom('span', null, ' B ')); - root.appendChild(goog.dom.createTextNode(' C ')); - goog.testing.dom.assertHtmlContentsMatch( - ' A <span> B </span> C ', root); - - root.innerHTML = ''; - root.appendChild(goog.dom.createTextNode(' A')); - root.appendChild(goog.dom.createDom('span', null, ' B')); - root.appendChild(goog.dom.createTextNode(' C')); - goog.testing.dom.assertHtmlContentsMatch( - ' A<span> B</span> C', root); - } - - function testAssertHtmlMatchesWithWhitespaceAndNesting() { - root.innerHTML = ''; - root.appendChild(goog.dom.createDom('div', null, - goog.dom.createDom('b', null, ' A '), - goog.dom.createDom('b', null, ' B '))); - root.appendChild(goog.dom.createDom('div', null, - goog.dom.createDom('b', null, ' C '), - goog.dom.createDom('b', null, ' D '))); - - goog.testing.dom.assertHtmlContentsMatch( - '<div><b> A </b><b> B </b></div>' + - '<div><b> C </b><b> D </b></div>', root); - - root.innerHTML = ''; - root.appendChild(goog.dom.createDom('b', null, - goog.dom.createDom('b', null, - goog.dom.createDom('b', null, ' A ')))); - root.appendChild(goog.dom.createDom('b', null, ' B ')); - - goog.testing.dom.assertHtmlContentsMatch( - '<b><b><b> A </b></b></b><b> B </b>', root); - - root.innerHTML = ''; - root.appendChild(goog.dom.createDom('div', null, - goog.dom.createDom('b', null, - goog.dom.createDom('b', null, ' A ')))); - root.appendChild(goog.dom.createDom('b', null, ' B ')); - - goog.testing.dom.assertHtmlContentsMatch( - '<div><b><b> A </b></b></div><b> B </b>', root); - - root.innerHTML = ' '; - goog.testing.dom.assertHtmlContentsMatch( - ' ', root); - } - - function testAssertHtmlMatches() { - // Since assertHtmlMatches is based on assertHtmlContentsMatch, we leave the - // majority of edge case testing to the above. Here we just do a sanity - // check. - goog.testing.dom.assertHtmlMatches('<div>abc</div>', '<div>abc</div>'); - goog.testing.dom.assertHtmlMatches('<div>abc</div>', '<div>abc</div> '); - goog.testing.dom.assertHtmlMatches( - '<div style="font-size: 1px; color: red">abc</div>', - '<div style="color: red; font-size: 1px;;">abc</div>'); - - var e = assertThrows('Should fail due to mismatched text', function() { - goog.testing.dom.assertHtmlMatches('<div>abc</div>', '<div>abd</div>'); - }); - assertContains('Text should match', e.message); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/expectedfailures.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/expectedfailures.js.svn-base deleted file mode 100644 index 33fc553..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/expectedfailures.js.svn-base +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Helper class to allow for expected unit test failures. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.testing.ExpectedFailures'); - -goog.require('goog.debug.DivConsole'); -goog.require('goog.debug.Logger'); -goog.require('goog.dom'); -goog.require('goog.dom.TagName'); -goog.require('goog.events'); -goog.require('goog.events.EventType'); -goog.require('goog.style'); -goog.require('goog.testing.JsUnitException'); -goog.require('goog.testing.TestCase'); -goog.require('goog.testing.asserts'); - - - -/** - * Helper class for allowing some unit tests to fail, particularly designed to - * mark tests that should be fixed on a given browser. - * - * <pre> - * var expectedFailures = new goog.testing.ExpectedFailures(); - * - * function tearDown() { - * expectedFailures.handleTearDown(); - * } - * - * function testSomethingThatBreaksInWebKit() { - * expectedFailures.expectFailureFor(goog.userAgent.WEBKIT); - * - * try { - * ... - * assert(somethingThatFailsInWebKit); - * ... - * } catch (e) { - * expectedFailures.handleException(e); - * } - * } - * </pre> - * - * @constructor - */ -goog.testing.ExpectedFailures = function() { - goog.testing.ExpectedFailures.setUpConsole_(); - this.reset_(); -}; - - -/** - * The lazily created debugging console. - * @type {goog.debug.DivConsole?} - * @private - */ -goog.testing.ExpectedFailures.console_ = null; - - -/** - * Logger for the expected failures. - * @type {goog.debug.Logger} - * @private - */ -goog.testing.ExpectedFailures.prototype.logger_ = - goog.debug.Logger.getLogger('goog.testing.ExpectedFailures'); - - -/** - * Whether or not we are expecting failure. - * @type {boolean} - * @private - */ -goog.testing.ExpectedFailures.prototype.expectingFailure_; - - -/** - * The string to emit upon an expected failure. - * @type {string} - * @private - */ -goog.testing.ExpectedFailures.prototype.failureMessage_; - - -/** - * An array of suppressed failures. - * @type {Array} - * @private - */ -goog.testing.ExpectedFailures.prototype.suppressedFailures_; - - -/** - * Sets up the debug console, if it isn't already set up. - * @private - */ -goog.testing.ExpectedFailures.setUpConsole_ = function() { - if (!goog.testing.ExpectedFailures.console_) { - var xButton = goog.dom.createDom(goog.dom.TagName.DIV, { - 'style': 'position: absolute; border-left:1px solid #333;' + - 'border-bottom:1px solid #333; right: 0; top: 0; width: 1em;' + - 'height: 1em; cursor: pointer; background-color: #cde;' + - 'text-align: center; color: black' - }, 'X'); - var div = goog.dom.createDom(goog.dom.TagName.DIV, { - 'style': 'position: absolute; border: 1px solid #333; right: 10px;' + - 'top : 10px; width: 400px; display: none' - }, xButton); - document.body.appendChild(div); - goog.events.listen(xButton, goog.events.EventType.CLICK, function() { - goog.style.showElement(div, false); - }); - - goog.testing.ExpectedFailures.console_ = new goog.debug.DivConsole(div); - goog.testing.ExpectedFailures.prototype.logger_.addHandler( - goog.bind(goog.style.showElement, null, div, true)); - goog.testing.ExpectedFailures.prototype.logger_.addHandler( - goog.bind(goog.testing.ExpectedFailures.console_.addLogRecord, - goog.testing.ExpectedFailures.console_)); - } -}; - - -/** - * Register to expect failure for the given condition. Multiple calls to this - * function act as a boolean OR. The first applicable message will be used. - * @param {boolean} condition Whether to expect failure. - * @param {string=} opt_message Descriptive message of this expected failure. - */ -goog.testing.ExpectedFailures.prototype.expectFailureFor = function( - condition, opt_message) { - this.expectingFailure_ = this.expectingFailure_ || condition; - if (condition) { - this.failureMessage_ = this.failureMessage_ || opt_message || ''; - } -}; - - -/** - * Determines if the given exception was expected. - * @param {Object} ex The exception to check. - * @return {boolean} Whether the exception was expected. - */ -goog.testing.ExpectedFailures.prototype.isExceptionExpected = function(ex) { - return this.expectingFailure_ && ex instanceof goog.testing.JsUnitException; -}; - - -/** - * Handle an exception, suppressing it if it is a unit test failure that we - * expected. - * @param {Error} ex The exception to handle. - */ -goog.testing.ExpectedFailures.prototype.handleException = function(ex) { - if (this.isExceptionExpected(ex)) { - this.logger_.info('Suppressing test failure in ' + - goog.testing.TestCase.currentTestName + ':' + - (this.failureMessage_ ? '\n(' + this.failureMessage_ + ')' : ''), - ex); - this.suppressedFailures_.push(ex); - return; - } - - // Rethrow the exception if we weren't expecting it or if it is a normal - // exception. - throw ex; -}; - - -/** - * Run the given function, catching any expected failures. - * @param {Function} func The function to run. - * @param {boolean=} opt_lenient Whether to ignore if the expected failures - * didn't occur. In this case a warning will be logged in handleTearDown. - */ -goog.testing.ExpectedFailures.prototype.run = function(func, opt_lenient) { - try { - func(); - } catch (ex) { - this.handleException(ex); - } - - if (!opt_lenient && this.expectingFailure_ && - !this.suppressedFailures_.length) { - fail(this.getExpectationMessage_()); - } -}; - - -/** - * @return {string} A warning describing an expected failure that didn't occur. - * @private - */ -goog.testing.ExpectedFailures.prototype.getExpectationMessage_ = function() { - return 'Expected a test failure in \'' + - goog.testing.TestCase.currentTestName + '\' but the test passed.'; -}; - - -/** - * Handle the tearDown phase of a test, alerting the user if an expected test - * was not suppressed. - */ -goog.testing.ExpectedFailures.prototype.handleTearDown = function() { - if (this.expectingFailure_ && !this.suppressedFailures_.length) { - this.logger_.warning(this.getExpectationMessage_()); - } - this.reset_(); -}; - - -/** - * Reset internal state. - * @private - */ -goog.testing.ExpectedFailures.prototype.reset_ = function() { - this.expectingFailure_ = false; - this.failureMessage_ = ''; - this.suppressedFailures_ = []; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/expectedfailures_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/expectedfailures_test.html.svn-base deleted file mode 100644 index 899d6c9..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/expectedfailures_test.html.svn-base +++ /dev/null @@ -1,122 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.ExpectedFailures</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.ExpectedFailures'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script type="text/javascript"> - var count, expectedFailures, lastLevel, lastMessage; - - // Stub out the logger. - goog.testing.ExpectedFailures.prototype.logger_.log = function(level, - message) { - lastLevel = level; - lastMessage = message; - count++; - }; - - function setUp() { - expectedFailures = new goog.testing.ExpectedFailures(); - count = 0; - lastLevel = lastMessage = ''; - } - - // Individual test methods. - - function testNoExpectedFailure() { - expectedFailures.handleTearDown() - } - - function testPreventExpectedFailure() { - expectedFailures.expectFailureFor(true); - - expectedFailures.handleException(new goog.testing.JsUnitException('', '')); - assertEquals('Should have logged a message', 1, count); - assertEquals('Should have logged an info message', - goog.debug.Logger.Level.INFO, lastLevel); - assertContains('Should log a suppression message', - 'Suppressing test failure', lastMessage); - - expectedFailures.handleTearDown(); - assertEquals('Should not have logged another message', 1, count); - } - - function testDoNotPreventException() { - var ex = 'exception'; - expectedFailures.expectFailureFor(false); - var e = assertThrows('Should have rethrown exception', function() { - expectedFailures.handleException(ex); - }); - assertEquals('Should rethrow same exception', ex, e); - } - - function testExpectedFailureDidNotOccur() { - expectedFailures.expectFailureFor(true); - - expectedFailures.handleTearDown(); - assertEquals('Should have logged a message', 1, count); - assertEquals('Should have logged a warning', - goog.debug.Logger.Level.WARNING, lastLevel); - assertContains('Should log a suppression message', - 'Expected a test failure', lastMessage); - } - - function testRun() { - expectedFailures.expectFailureFor(true); - - expectedFailures.run(function() { - fail('Expected failure'); - }); - - assertEquals('Should have logged a message', 1, count); - assertEquals('Should have logged an info message', - goog.debug.Logger.Level.INFO, lastLevel); - assertContains('Should log a suppression message', - 'Suppressing test failure', lastMessage); - - expectedFailures.handleTearDown(); - assertEquals('Should not have logged another message', 1, count); - } - - function testRunStrict() { - expectedFailures.expectFailureFor(true); - - var ex = assertThrows(function() { - expectedFailures.run(function() { - // Doesn't fail! - }); - }); - assertContains( - "Expected a test failure in 'testRunStrict' but the test passed.", - ex.message); - } - - function testRunLenient() { - expectedFailures.expectFailureFor(true); - - expectedFailures.run(function() { - // Doesn't fail! - }, true); - expectedFailures.handleTearDown(); - assertEquals('Should have logged a message', 1, count); - assertEquals('Should have logged a warning', - goog.debug.Logger.Level.WARNING, lastLevel); - assertContains('Should log a suppression message', - 'Expected a test failure', lastMessage); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/functionmock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/functionmock.js.svn-base deleted file mode 100644 index f00bb61..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/functionmock.js.svn-base +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Enable mocking of functions not attached to objects - * whether they be global / top-level or anonymous methods / closures. - * - * See the unit tests for usage. - * - */ - -goog.provide('goog.testing'); -goog.provide('goog.testing.FunctionMock'); -goog.provide('goog.testing.GlobalFunctionMock'); -goog.provide('goog.testing.MethodMock'); - -goog.require('goog.object'); -goog.require('goog.testing.LooseMock'); -goog.require('goog.testing.Mock'); -goog.require('goog.testing.MockInterface'); -goog.require('goog.testing.PropertyReplacer'); -goog.require('goog.testing.StrictMock'); - - -/** - * Class used to mock a function. Useful for mocking closures and anonymous - * callbacks etc. Creates a function object that extends goog.testing.Mock. - * @param {string=} opt_functionName The optional name of the function to mock. - * Set to '[anonymous mocked function]' if not passed in. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked function. - * @suppress {missingProperties} Mocks do not fit in the type system well. - */ -goog.testing.FunctionMock = function(opt_functionName, opt_strictness) { - var fn = function() { - var args = Array.prototype.slice.call(arguments); - args.splice(0, 0, opt_functionName || '[anonymous mocked function]'); - return fn.$mockMethod.apply(fn, args); - }; - var base = opt_strictness === goog.testing.Mock.LOOSE ? - goog.testing.LooseMock : goog.testing.StrictMock; - goog.object.extend(fn, new base({})); - - return /** @type {goog.testing.MockInterface} */ (fn); -}; - - -/** - * Mocks an existing function. Creates a goog.testing.FunctionMock - * and registers it in the given scope with the name specified by functionName. - * @param {Object} scope The scope of the method to be mocked out. - * @param {string} functionName The name of the function we're going to mock. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked method. - */ -goog.testing.MethodMock = function(scope, functionName, opt_strictness) { - if (!(functionName in scope)) { - throw Error(functionName + ' is not a property of the given scope.'); - } - - var fn = goog.testing.FunctionMock(functionName, opt_strictness); - - fn.$propertyReplacer_ = new goog.testing.PropertyReplacer(); - fn.$propertyReplacer_.set(scope, functionName, fn); - fn.$tearDown = goog.testing.MethodMock.$tearDown; - - return fn; -}; - - -/** - * Resets the global function that we mocked back to its original state. - * @this {goog.testing.MockInterface} - */ -goog.testing.MethodMock.$tearDown = function() { - this.$propertyReplacer_.reset(); -}; - - -/** - * Mocks a global / top-level function. Creates a goog.testing.MethodMock - * in the global scope with the name specified by functionName. - * @param {string} functionName The name of the function we're going to mock. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked global function. - */ -goog.testing.GlobalFunctionMock = function(functionName, opt_strictness) { - return goog.testing.MethodMock(goog.global, functionName, opt_strictness); -}; - - -/** - * Convenience method for creating a mock for a function. - * @param {string=} opt_functionName The optional name of the function to mock - * set to '[anonymous mocked function]' if not passed in. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked function. - */ -goog.testing.createFunctionMock = function(opt_functionName, opt_strictness) { - return goog.testing.FunctionMock(opt_functionName, opt_strictness); -}; - - -/** - * Convenience method for creating a mock for a method. - * @param {Object} scope The scope of the method to be mocked out. - * @param {string} functionName The name of the function we're going to mock. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked global function. - */ -goog.testing.createMethodMock = function(scope, functionName, opt_strictness) { - return goog.testing.MethodMock(scope, functionName, opt_strictness); -}; - - -/** - * Convenience method for creating a mock for a constructor. Copies class - * members to the mock. - * - * <p>When mocking a constructor to return a mocked instance, remember to create - * the instance mock before mocking the constructor. If you mock the constructor - * first, then the mock framework will be unable to examine the prototype chain - * when creating the mock instance. - * @param {Object} scope The scope of the constructor to be mocked out. - * @param {string} constructorName The name of the constructor we're going to - * mock. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked constructor. - */ -goog.testing.createConstructorMock = function(scope, constructorName, - opt_strictness) { - var realConstructor = scope[constructorName]; - var constructorMock = goog.testing.MethodMock(scope, constructorName, - opt_strictness); - - // Copy class members from the real constructor to the mock. Do not copy - // the closure superClass_ property (see goog.inherits), the built-in - // prototype property, or properties added to Function.prototype - // (see goog.MODIFY_FUNCTION_PROTOTYPES in closure/base.js). - for (var property in realConstructor) { - if (property != 'superClass_' && - property != 'prototype' && - realConstructor.hasOwnProperty(property)) { - constructorMock[property] = realConstructor[property]; - } - } - return constructorMock; -}; - - -/** - * Convenience method for creating a mocks for a global / top-level function. - * @param {string} functionName The name of the function we're going to mock. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked global function. - */ -goog.testing.createGlobalFunctionMock = function(functionName, opt_strictness) { - return goog.testing.GlobalFunctionMock(functionName, opt_strictness); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/functionmock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/functionmock_test.html.svn-base deleted file mode 100644 index e2e2515..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/functionmock_test.html.svn-base +++ /dev/null @@ -1,511 +0,0 @@ -<!DOCTYPE html> -<!-- - - Test mocking global / top-level functions - ---> - -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Global Mock Unit Test</title> -<script src="../base.js"></script> -<script> - goog.require('goog.array'); - goog.require('goog.testing.asserts'); - goog.require('goog.testing.FunctionMock'); - goog.require('goog.testing.GlobalFunctionMock'); - goog.require('goog.testing.MethodMock'); - goog.require('goog.testing.Mock'); - goog.require('goog.testing.StrictMock'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - -// Global scope so we can tear it down safely -var mockGlobal; - -function tearDown() { - if (mockGlobal) { - mockGlobal.$tearDown(); - } -} - - -//----- Tests for goog.testing.FunctionMock - -function testMockFunctionCallOrdering() { - var doOneTest = function(mockFunction, success, expected_args, actual_args) { - goog.array.forEach(expected_args, function(arg) { mockFunction(arg); }); - mockFunction.$replay(); - var callFunction = function() { - goog.array.forEach(actual_args, function(arg) { mockFunction(arg); }); - mockFunction.$verify(); - }; - if (success) { - callFunction(); - } else { - assertThrows(callFunction); - } - }; - - var doTest = function(strict_ok, loose_ok, expected_args, actual_args) { - doOneTest(goog.testing.createFunctionMock(), strict_ok, - expected_args, actual_args); - doOneTest(goog.testing.createFunctionMock('name'), strict_ok, - expected_args, actual_args); - doOneTest(goog.testing.createFunctionMock('name', goog.testing.Mock.STRICT), - strict_ok, expected_args, actual_args); - doOneTest(goog.testing.createFunctionMock('name', goog.testing.Mock.LOOSE), - loose_ok, expected_args, actual_args); - } - - doTest(true, true, [1, 2], [1, 2]); - doTest(false, true, [1, 2], [2, 1]); - doTest(false, false, [1, 2], [2, 2]); - doTest(false, false, [1, 2], [1]); - doTest(false, false, [1, 2], [1, 1]); - doTest(false, false, [1, 2], [1]); -} - -function testMocksFunctionWithNoArgs() { - var mockFoo = goog.testing.createFunctionMock(); - mockFoo(); - mockFoo.$replay(); - mockFoo(); - mockFoo.$verify(); -} - -function testMocksFunctionWithOneArg() { - var mockFoo = goog.testing.createFunctionMock(); - mockFoo('x'); - mockFoo.$replay(); - mockFoo('x'); - mockFoo.$verify(); -} - -function testMocksFunctionWithMultipleArgs() { - var mockFoo = goog.testing.createFunctionMock(); - mockFoo('x', 'y'); - mockFoo.$replay(); - mockFoo('x', 'y'); - mockFoo.$verify(); -} - -function testFailsIfCalledWithIncorrectArgs() { - var mockFoo = goog.testing.createFunctionMock(); - - mockFoo(); - mockFoo.$replay(); - assertThrows(function() {mockFoo('x');}); - mockFoo.$reset(); - - mockFoo('x'); - mockFoo.$replay(); - assertThrows(function() {mockFoo();}); - mockFoo.$reset(); - - mockFoo('x'); - mockFoo.$replay(); - assertThrows(function() {mockFoo('x', 'y');}); - mockFoo.$reset(); - - mockFoo('x', 'y'); - mockFoo.$replay(); - assertThrows(function() {mockFoo('x');}); - mockFoo.$reset(); - - mockFoo('correct'); - mockFoo.$replay(); - assertThrows(function() {mockFoo('wrong');}); - mockFoo.$reset(); - - mockFoo('correct', 'args'); - mockFoo.$replay(); - assertThrows(function() {mockFoo('wrong', 'args');}); - mockFoo.$reset(); -} - -function testMocksFunctionWithReturnValue() { - var mockFoo = goog.testing.createFunctionMock(); - mockFoo().$returns('bar'); - mockFoo.$replay(); - assertEquals('bar', mockFoo()); - mockFoo.$verify(); -} - -function testFunctionMockWorksWhenPassedAsACallback() { - var invoker = { - register: function(callback) { - this.callback = callback; - }, - - invoke: function(args) { - return this.callback(args); - } - }; - - var mockFunction = goog.testing.createFunctionMock(); - mockFunction('bar').$returns('baz'); - - mockFunction.$replay(); - invoker.register(mockFunction); - assertEquals('baz', invoker.invoke('bar')); - mockFunction.$verify(); -} - -function testFunctionMockQuacksLikeAStrictMock() { - var mockFunction = goog.testing.createFunctionMock(); - assertQuacksLike(mockFunction, goog.testing.StrictMock); -} - - -//----- Global functions for goog.testing.GlobalFunctionMock to mock - -function globalFoo() { - return 'I am Spartacus!'; -} - -function globalBar(who, what) { - return [who, 'is', what].join(' '); -} - - -//----- Tests for goog.testing.createGlobalFunctionMock - -function testMocksGlobalFunctionWithNoArgs() { - mockGlobal = goog.testing.createGlobalFunctionMock('globalFoo'); - mockGlobal().$returns('No, I am Spartacus!'); - - mockGlobal.$replay(); - assertEquals('No, I am Spartacus!', globalFoo()); - mockGlobal.$verify(); -} - -function testMocksGlobalFunctionUsingGlobalName() { - goog.testing.createGlobalFunctionMock('globalFoo'); - globalFoo().$returns('No, I am Spartacus!'); - - globalFoo.$replay(); - assertEquals('No, I am Spartacus!', globalFoo()); - globalFoo.$verify(); - globalFoo.$tearDown(); -} - -function testMocksGlobalFunctionWithArgs() { - var mockReturnValue = 'Noam is Chomsky!'; - mockGlobal = goog.testing.createGlobalFunctionMock('globalBar'); - mockGlobal('Noam', 'Spartacus').$returns(mockReturnValue); - - mockGlobal.$replay(); - assertEquals(mockReturnValue, globalBar('Noam', 'Spartacus')); - mockGlobal.$verify(); -} - -function testGlobalFunctionMockFailsWithIncorrectArgs() { - mockGlobal = goog.testing.createGlobalFunctionMock('globalBar'); - mockGlobal('a', 'b'); - - mockGlobal.$replay(); - - assertThrows('Mock should have failed because of incorrect arguments', - function() {globalBar('b', 'a')}); -} - -function testGlobalFunctionMockQuacksLikeAFunctionMock() { - mockGlobal = goog.testing.createGlobalFunctionMock('globalFoo'); - assertQuacksLike(mockGlobal, goog.testing.FunctionMock); -} - -function testMockedFunctionsAvailableInGlobalAndGoogGlobalAndWindowScope() { - mockGlobal = goog.testing.createGlobalFunctionMock('globalFoo'); - - // we expect this call 3 times through global, goog.global and window scope - mockGlobal().$times(3); - - mockGlobal.$replay(); - goog.global.globalFoo(); - window.globalFoo(); - globalFoo(); - mockGlobal.$verify(); -} - -function testTearDownRestoresOriginalGlobalFunction() { - mockGlobal = goog.testing.createGlobalFunctionMock('globalFoo'); - mockGlobal().$returns('No, I am Spartacus!'); - - mockGlobal.$replay(); - assertEquals('No, I am Spartacus!', globalFoo()); - mockGlobal.$tearDown(); - assertEquals('I am Spartacus!', globalFoo()); - mockGlobal.$verify(); -} - -function testTearDownHandlesMultipleMocking() { - var mock1 = goog.testing.createGlobalFunctionMock('globalFoo'); - var mock2 = goog.testing.createGlobalFunctionMock('globalFoo'); - var mock3 = goog.testing.createGlobalFunctionMock('globalFoo'); - mock1().$returns('No, I am Spartacus 1!'); - mock2().$returns('No, I am Spartacus 2!'); - mock3().$returns('No, I am Spartacus 3!'); - - mock1.$replay(); - mock2.$replay(); - mock3.$replay(); - assertEquals('No, I am Spartacus 3!', globalFoo()); - mock3.$tearDown(); - assertEquals('No, I am Spartacus 2!', globalFoo()); - mock2.$tearDown(); - assertEquals('No, I am Spartacus 1!', globalFoo()); - mock1.$tearDown(); - assertEquals('I am Spartacus!', globalFoo()); -} - -function testGlobalFunctionMockCallOrdering() { - var mock = goog.testing.createGlobalFunctionMock('globalFoo'); - mock(1); - mock(2); - mock.$replay(); - assertThrows(function(){globalFoo(2);}); - mock.$tearDown(); - - mock = goog.testing.createGlobalFunctionMock('globalFoo', - goog.testing.Mock.STRICT); - mock(1); - mock(2); - mock.$replay(); - globalFoo(1); - globalFoo(2); - mock.$verify(); - mock.$tearDown(); - - mock = goog.testing.createGlobalFunctionMock('globalFoo', - goog.testing.Mock.STRICT); - mock(1); - mock(2); - mock.$replay(); - assertThrows(function(){globalFoo(2);}); - mock.$tearDown(); - - mock = goog.testing.createGlobalFunctionMock('globalFoo', - goog.testing.Mock.LOOSE); - mock(1); - mock(2); - mock.$replay(); - globalFoo(2); - globalFoo(1); - mock.$verify(); - mock.$tearDown(); -} - -//----- Functions for goog.testing.MethodMock to mock - -var mynamespace = {}; - -mynamespace.myMethod = function() { - return 'I should be mocked.'; -}; - -function testMocksMethod() { - mockMethod = goog.testing.createMethodMock(mynamespace, 'myMethod'); - mockMethod().$returns('I have been mocked!'); - - mockMethod.$replay(); - assertEquals('I have been mocked!', mockMethod()); - mockMethod.$verify(); -} - -function testMocksMethodInNamespace() { - goog.testing.createMethodMock(mynamespace, 'myMethod'); - mynamespace.myMethod().$returns('I have been mocked!'); - - mynamespace.myMethod.$replay(); - assertEquals('I have been mocked!', mynamespace.myMethod()); - mynamespace.myMethod.$verify(); - mynamespace.myMethod.$tearDown(); -} - -function testMethodMockCanOnlyMockExistingMethods() { - assertThrows(function() { - goog.testing.createMethodMock(mynamespace, 'doesNotExist'); - }); -} - -function testMethodMockCallOrdering() { - goog.testing.createMethodMock(mynamespace, 'myMethod'); - mynamespace.myMethod(1); - mynamespace.myMethod(2); - mynamespace.myMethod.$replay(); - assertThrows(function(){mynamespace.myMethod(2);}); - mynamespace.myMethod.$tearDown(); - - goog.testing.createMethodMock(mynamespace, 'myMethod', - goog.testing.Mock.STRICT); - mynamespace.myMethod(1); - mynamespace.myMethod(2); - mynamespace.myMethod.$replay(); - mynamespace.myMethod(1); - mynamespace.myMethod(2); - mynamespace.myMethod.$verify(); - mynamespace.myMethod.$tearDown(); - - goog.testing.createMethodMock(mynamespace, 'myMethod', - goog.testing.Mock.STRICT); - mynamespace.myMethod(1); - mynamespace.myMethod(2); - mynamespace.myMethod.$replay(); - assertThrows(function(){mynamespace.myMethod(2);}); - mynamespace.myMethod.$tearDown(); - - goog.testing.createMethodMock(mynamespace, 'myMethod', - goog.testing.Mock.LOOSE); - mynamespace.myMethod(1); - mynamespace.myMethod(2); - mynamespace.myMethod.$replay(); - mynamespace.myMethod(2); - mynamespace.myMethod(1); - mynamespace.myMethod.$verify(); - mynamespace.myMethod.$tearDown(); -} - -//----- Functions for goog.testing.createConstructorMock to mock - -var constructornamespace = {}; - -constructornamespace.MyConstructor = function() { -}; - -constructornamespace.MyConstructor.prototype.myMethod = function() { - return 'I should be mocked.'; -}; - -constructornamespace.MyConstructorWithArgument = function(argument) { - this.argument_ = argument; -}; - -constructornamespace.MyConstructorWithArgument.prototype.myMethod = function() { - return this.argument_; -}; - -constructornamespace.MyConstructorWithClassMembers = function() { -}; - -constructornamespace.MyConstructorWithClassMembers.CONSTANT = 42; - -constructornamespace.MyConstructorWithClassMembers.classMethod = function() { - return 'class method return value'; -}; - -function testConstructorMock() { - var mockObject = - new goog.testing.StrictMock(constructornamespace.MyConstructor); - var mockConstructor = goog.testing.createConstructorMock( - constructornamespace, 'MyConstructor'); - mockConstructor().$returns(mockObject); - mockObject.myMethod().$returns('I have been mocked!'); - - mockConstructor.$replay(); - mockObject.$replay(); - assertEquals('I have been mocked!', - new constructornamespace.MyConstructor().myMethod()); - mockConstructor.$verify(); - mockObject.$verify(); - mockConstructor.$tearDown(); -} - -function testConstructorMockWithArgument() { - var mockObject = new goog.testing.StrictMock( - constructornamespace.MyConstructorWithArgument); - var mockConstructor = goog.testing.createConstructorMock( - constructornamespace, 'MyConstructorWithArgument'); - mockConstructor(goog.testing.mockmatchers.isString).$returns(mockObject); - mockObject.myMethod().$returns('I have been mocked!'); - - mockConstructor.$replay(); - mockObject.$replay(); - assertEquals('I have been mocked!', - new constructornamespace.MyConstructorWithArgument('I should be mocked.') - .myMethod()); - mockConstructor.$verify(); - mockObject.$verify(); - mockConstructor.$tearDown(); -} - -/** - * Test that class members are copied to the mock constructor. - */ -function testConstructorMockWithClassMembers() { - var mockConstructor = goog.testing.createConstructorMock( - constructornamespace, 'MyConstructorWithClassMembers'); - assertEquals(42, constructornamespace.MyConstructorWithClassMembers.CONSTANT); - assertEquals('class method return value', - constructornamespace.MyConstructorWithClassMembers.classMethod()); - mockConstructor.$tearDown(); -} - -function testConstructorMockCallOrdering() { - var instance = {}; - - goog.testing.createConstructorMock(constructornamespace, - 'MyConstructorWithArgument'); - constructornamespace.MyConstructorWithArgument(1).$returns(instance); - constructornamespace.MyConstructorWithArgument(2).$returns(instance); - constructornamespace.MyConstructorWithArgument.$replay(); - assertThrows( - function(){new constructornamespace.MyConstructorWithArgument(2);}); - constructornamespace.MyConstructorWithArgument.$tearDown(); - - goog.testing.createConstructorMock(constructornamespace, - 'MyConstructorWithArgument', - goog.testing.Mock.STRICT); - constructornamespace.MyConstructorWithArgument(1).$returns(instance); - constructornamespace.MyConstructorWithArgument(2).$returns(instance); - constructornamespace.MyConstructorWithArgument.$replay(); - new constructornamespace.MyConstructorWithArgument(1); - new constructornamespace.MyConstructorWithArgument(2); - constructornamespace.MyConstructorWithArgument.$verify(); - constructornamespace.MyConstructorWithArgument.$tearDown(); - - goog.testing.createConstructorMock(constructornamespace, - 'MyConstructorWithArgument', - goog.testing.Mock.STRICT); - constructornamespace.MyConstructorWithArgument(1).$returns(instance); - constructornamespace.MyConstructorWithArgument(2).$returns(instance); - constructornamespace.MyConstructorWithArgument.$replay(); - assertThrows( - function(){new constructornamespace.MyConstructorWithArgument(2);}); - constructornamespace.MyConstructorWithArgument.$tearDown(); - - goog.testing.createConstructorMock(constructornamespace, - 'MyConstructorWithArgument', - goog.testing.Mock.LOOSE); - constructornamespace.MyConstructorWithArgument(1).$returns(instance); - constructornamespace.MyConstructorWithArgument(2).$returns(instance); - constructornamespace.MyConstructorWithArgument.$replay(); - new constructornamespace.MyConstructorWithArgument(2); - new constructornamespace.MyConstructorWithArgument(1); - constructornamespace.MyConstructorWithArgument.$verify(); - constructornamespace.MyConstructorWithArgument.$tearDown(); -} - -//----- Helper assertions - -function assertQuacksLike(obj, target) { - for (meth in target.prototype) { - if (!goog.string.endsWith(meth, '_')) { - assertNotUndefined('Should have implemented '+ meth +'()', obj[meth]); - } - } -} -</script> - -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/graphics.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/graphics.js.svn-base deleted file mode 100644 index fea11c8..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/graphics.js.svn-base +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Testing utilities for DOM related tests. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.testing.graphics'); - -goog.require('goog.graphics.Path.Segment'); -goog.require('goog.testing.asserts'); - - -/** - * Array mapping numeric segment constant to a descriptive character. - * @type {Array.<string>} - * @private - */ -goog.testing.graphics.SEGMENT_NAMES_ = function() { - var arr = []; - arr[goog.graphics.Path.Segment.MOVETO] = 'M'; - arr[goog.graphics.Path.Segment.LINETO] = 'L'; - arr[goog.graphics.Path.Segment.CURVETO] = 'C'; - arr[goog.graphics.Path.Segment.ARCTO] = 'A'; - arr[goog.graphics.Path.Segment.CLOSE] = 'X'; - return arr; -}(); - - -/** - * Test if the given path matches the expected array of commands and parameters. - * @param {Array.<string|number>} expected The expected array of commands and - * parameters. - * @param {goog.graphics.Path} path The path to test against. - */ -goog.testing.graphics.assertPathEquals = function(expected, path) { - var actual = []; - path.forEachSegment(function(seg, args) { - actual.push(goog.testing.graphics.SEGMENT_NAMES_[seg]); - Array.prototype.push.apply(actual, args); - }); - assertEquals(expected.length, actual.length); - for (var i = 0; i < expected.length; i++) { - if (goog.isNumber(expected[i])) { - assertTrue(goog.isNumber(actual[i])); - assertRoughlyEquals(expected[i], actual[i], 0.01); - } else { - assertEquals(expected[i], actual[i]); - } - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/jsunit.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/jsunit.js.svn-base deleted file mode 100644 index 97d343d..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/jsunit.js.svn-base +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with JsUnit. Writes out the JsUnit file - * that needs to be included in every unit test. - * - * Testing code should not have dependencies outside of goog.testing so as to - * reduce the chance of masking missing dependencies. - * - */ - -goog.provide('goog.testing.jsunit'); - -goog.require('goog.testing.TestCase'); -goog.require('goog.testing.TestRunner'); - - -/** - * Base path for JsUnit app files, relative to Closure's base path. - * @type {string} - */ -goog.testing.jsunit.BASE_PATH = - '../../third_party/java/jsunit/core/app/'; - - -/** - * Filename for the core JS Unit script. - * @type {string} - */ -goog.testing.jsunit.CORE_SCRIPT = - goog.testing.jsunit.BASE_PATH + 'jsUnitCore.js'; - - -/** - * @define {boolean} If this code is being parsed by JsTestC, we let it disable - * the onload handler to avoid running the test in JsTestC. - */ -goog.testing.jsunit.AUTO_RUN_ONLOAD = true; - - -(function() { - - // Store a reference to the window's timeout so that it can't be overridden - // by tests. - var realTimeout = window.setTimeout; - - // Check for JsUnit's test runner (need to check for >2.2 and <=2.2) - if (top['JsUnitTestManager'] || top['jsUnitTestManager']) { - // Running inside JsUnit so add support code. - var path = goog.basePath + goog.testing.jsunit.CORE_SCRIPT; - document.write('<script type="text/javascript" src="' + - path + '"></' + 'script>'); - - } else { - - // Create a test runner. - var tr = new goog.testing.TestRunner(); - - // Export it so that it can be queried by Selenium and tests that use a - // compiled test runner. - goog.exportSymbol('G_testRunner', tr); - goog.exportSymbol('G_testRunner.initialize', tr.initialize); - goog.exportSymbol('G_testRunner.isInitialized', tr.isInitialized); - goog.exportSymbol('G_testRunner.isFinished', tr.isFinished); - goog.exportSymbol('G_testRunner.isSuccess', tr.isSuccess); - goog.exportSymbol('G_testRunner.getReport', tr.getReport); - goog.exportSymbol('G_testRunner.getRunTime', tr.getRunTime); - goog.exportSymbol('G_testRunner.getNumFilesLoaded', tr.getNumFilesLoaded); - goog.exportSymbol('G_testRunner.setStrict', tr.setStrict); - goog.exportSymbol('G_testRunner.logTestFailure', tr.logTestFailure); - - // Export debug as a global function for JSUnit compatibility. This just - // calls log on the current test case. - if (!goog.global['debug']) { - goog.exportSymbol('debug', goog.bind(tr.log, tr)); - } - - // If the application has defined a global error filter, set it now. This - // allows users who use a base test include to set the error filter before - // the testing code is loaded. - if (goog.global['G_errorFilter']) { - tr.setErrorFilter(goog.global['G_errorFilter']); - } - - // Add an error handler to report errors that may occur during - // initialization of the page. - var onerror = window.onerror; - window.onerror = function(error, url, line) { - // Call any existing onerror handlers. - if (onerror) { - onerror(error, url, line); - } - if (typeof error == 'object') { - // Webkit started passing an event object as the only argument to - // window.onerror. It doesn't contain an error message, url or line - // number. We therefore log as much info as we can. - if (error.target && error.target.tagName == 'SCRIPT') { - tr.logError('UNKNOWN ERROR: Script ' + error.target.src); - } else { - tr.logError('UNKNOWN ERROR: No error information available.'); - } - } else { - tr.logError('JS ERROR: ' + error + '\nURL: ' + url + '\nLine: ' + line); - } - }; - - // Create an onload handler, if the test runner hasn't been initialized then - // no test has been registered with the test runner by the test file. We - // then create a new test case and auto discover any tests in the global - // scope. If this code is being parsed by JsTestC, we let it disable the - // onload handler to avoid running the test in JsTestC. - if (goog.testing.jsunit.AUTO_RUN_ONLOAD) { - var onload = window.onload; - window.onload = function() { - // Call any existing onload handlers. - if (onload) { - onload(); - } - // Wait 500ms longer so that we don't interfere with Selenium. - realTimeout(function() { - if (!tr.initialized) { - var test = new goog.testing.TestCase(document.title); - test.autoDiscoverTests(); - tr.initialize(test); - } - tr.execute(); - }, 500); - window.onload = null; - }; - } - } -})(); diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/loosemock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/loosemock.js.svn-base deleted file mode 100644 index 182bb3b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/loosemock.js.svn-base +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview This file defines a loose mock implementation. - */ - -goog.provide('goog.testing.LooseExpectationCollection'); -goog.provide('goog.testing.LooseMock'); - -goog.require('goog.array'); -goog.require('goog.structs.Map'); -goog.require('goog.testing.Mock'); - - - -/** - * This class is an ordered collection of expectations for one method. Since - * the loose mock does most of its verification at the time of $verify, this - * class is necessary to manage the return/throw behavior when the mock is - * being called. - * @constructor - */ -goog.testing.LooseExpectationCollection = function() { - /** - * The list of expectations. All of these should have the same name. - * @type {Array.<goog.testing.MockExpectation>} - * @private - */ - this.expectations_ = []; -}; - - -/** - * Adds an expectation to this collection. - * @param {goog.testing.MockExpectation} expectation The expectation to add. - */ -goog.testing.LooseExpectationCollection.prototype.addExpectation = - function(expectation) { - this.expectations_.push(expectation); -}; - - -/** - * Gets the list of expectations in this collection. - * @return {Array.<goog.testing.MockExpectation>} The array of expectations. - */ -goog.testing.LooseExpectationCollection.prototype.getExpectations = function() { - return this.expectations_; -}; - - - -/** - * This is a mock that does not care about the order of method calls. As a - * result, it won't throw exceptions until verify() is called. The only - * exception is that if a method is called that has no expectations, then an - * exception will be thrown. - * @param {Object} objectToMock The object to mock. - * @param {boolean=} opt_ignoreUnexpectedCalls Whether to ignore unexpected - * calls. - * @param {boolean=} opt_mockStaticMethods An optional argument denoting that - * a mock should be constructed from the static functions of a class. - * @param {boolean=} opt_createProxy An optional argument denoting that - * a proxy for the target mock should be created. - * @constructor - * @extends {goog.testing.Mock} - */ -goog.testing.LooseMock = function(objectToMock, opt_ignoreUnexpectedCalls, - opt_mockStaticMethods, opt_createProxy) { - goog.testing.Mock.call(this, objectToMock, opt_mockStaticMethods, - opt_createProxy); - - /** - * A map of method names to a LooseExpectationCollection for that method. - * @type {goog.structs.Map} - * @private - */ - this.$expectations_ = new goog.structs.Map(); - - /** - * The calls that have been made; we cache them to verify at the end. Each - * element is an array where the first element is the name, and the second - * element is the arguments. - * @type {Array.<Array.<*>>} - * @private - */ - this.$calls_ = []; - - /** - * Whether to ignore unexpected calls. - * @type {boolean} - * @private - */ - this.$ignoreUnexpectedCalls_ = !!opt_ignoreUnexpectedCalls; -}; -goog.inherits(goog.testing.LooseMock, goog.testing.Mock); - - -/** - * A setter for the ignoreUnexpectedCalls field. - * @param {boolean} ignoreUnexpectedCalls Whether to ignore unexpected calls. - * @return {goog.testing.LooseMock} This mock object. - */ -goog.testing.LooseMock.prototype.$setIgnoreUnexpectedCalls = function( - ignoreUnexpectedCalls) { - this.$ignoreUnexpectedCalls_ = ignoreUnexpectedCalls; - return this; -}; - - -/** @override */ -goog.testing.LooseMock.prototype.$recordExpectation = function() { - if (!this.$expectations_.containsKey(this.$pendingExpectation.name)) { - this.$expectations_.set(this.$pendingExpectation.name, - new goog.testing.LooseExpectationCollection()); - } - - var collection = this.$expectations_.get(this.$pendingExpectation.name); - collection.addExpectation(this.$pendingExpectation); -}; - - -/** @override */ -goog.testing.LooseMock.prototype.$recordCall = function(name, args) { - if (!this.$expectations_.containsKey(name)) { - if (this.$ignoreUnexpectedCalls_) { - return; - } - this.$throwCallException(name, args); - } - - // Start from the beginning of the expectations for this name, - // and iterate over them until we find an expectation that matches - // and also has calls remaining. - var collection = this.$expectations_.get(name); - var matchingExpectation = null; - var expectations = collection.getExpectations(); - for (var i = 0; i < expectations.length; i++) { - var expectation = expectations[i]; - if (this.$verifyCall(expectation, name, args)) { - matchingExpectation = expectation; - if (expectation.actualCalls < expectation.maxCalls) { - break; - } // else continue and see if we can find something that does match - } - } - if (matchingExpectation == null) { - this.$throwCallException(name, args, expectation); - } - - matchingExpectation.actualCalls++; - if (matchingExpectation.actualCalls > matchingExpectation.maxCalls) { - this.$throwException('Too many calls to ' + matchingExpectation.name + - '\nExpected: ' + matchingExpectation.maxCalls + ' but was: ' + - matchingExpectation.actualCalls); - } - - this.$calls_.push([name, args]); - return this.$do(matchingExpectation, args); -}; - - -/** @override */ -goog.testing.LooseMock.prototype.$reset = function() { - goog.testing.LooseMock.superClass_.$reset.call(this); - - this.$expectations_ = new goog.structs.Map(); - this.$calls_ = []; -}; - - -/** @override */ -goog.testing.LooseMock.prototype.$replay = function() { - goog.testing.LooseMock.superClass_.$replay.call(this); - - // Verify that there are no expectations that can never be reached. - // This can't catch every situation, but it is a decent sanity check - // and it's similar to the behavior of EasyMock in java. - var collections = this.$expectations_.getValues(); - for (var i = 0; i < collections.length; i++) { - var expectations = collections[i].getExpectations(); - for (var j = 0; j < expectations.length; j++) { - var expectation = expectations[j]; - // If this expectation can be called infinite times, then - // check if any subsequent expectation has the exact same - // argument list. - if (!isFinite(expectation.maxCalls)) { - for (var k = j + 1; k < expectations.length; k++) { - var laterExpectation = expectations[k]; - if (laterExpectation.minCalls > 0 && - goog.array.equals(expectation.argumentList, - laterExpectation.argumentList)) { - var name = expectation.name; - var argsString = this.$argumentsAsString(expectation.argumentList); - this.$throwException([ - 'Expected call to ', name, ' with arguments ', argsString, - ' has an infinite max number of calls; can\'t expect an', - ' identical call later with a positive min number of calls' - ].join('')); - } - } - } - } - } -}; - - -/** @override */ -goog.testing.LooseMock.prototype.$verify = function() { - goog.testing.LooseMock.superClass_.$verify.call(this); - var collections = this.$expectations_.getValues(); - - for (var i = 0; i < collections.length; i++) { - var expectations = collections[i].getExpectations(); - for (var j = 0; j < expectations.length; j++) { - var expectation = expectations[j]; - if (expectation.actualCalls > expectation.maxCalls) { - this.$throwException('Too many calls to ' + expectation.name + - '\nExpected: ' + expectation.maxCalls + ' but was: ' + - expectation.actualCalls); - } else if (expectation.actualCalls < expectation.minCalls) { - this.$throwException('Not enough calls to ' + expectation.name + - '\nExpected: ' + expectation.minCalls + ' but was: ' + - expectation.actualCalls); - } - } - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/loosemock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/loosemock_test.html.svn-base deleted file mode 100644 index bae04f3..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/loosemock_test.html.svn-base +++ /dev/null @@ -1,343 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.LooseMock</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.LooseMock'); - goog.require('goog.testing.PropertyReplacer'); - goog.require('goog.testing.jsunit'); - goog.require('goog.testing.mockmatchers'); -</script> -</head> -<body> -<script> - // The object that we will be mocking - var RealObject = function() { - }; - - RealObject.prototype.a = function() { - fail('real object should never be called'); - }; - - RealObject.prototype.b = function() { - fail('real object should never be called'); - }; - - var mock; - - var stubs; - - function setUp() { - var obj = new RealObject(); - mock = new goog.testing.LooseMock(obj); - stubs = new goog.testing.PropertyReplacer(); - } - - function tearDown() { - stubs.reset(); - } - - /* - * Calling this method evades the logTestFailure in - * goog.testing.Mock.prototype.$recordAndThrow, so it doesn't look like the - * test failed. - */ - function silenceFailureLogging() { - if (goog.global['G_testRunner']) { - stubs.set(goog.global['G_testRunner'], - 'logTestFailure', goog.nullFunction); - } - } - - function unsilenceFailureLogging() { - stubs.reset(); - } - - /** - * Version of assertThrows that doesn't log the exception generated by the - * mocks under test. - * TODO: would be nice to check that a particular substring is in the thrown - * message so we know it's not something dumb like a syntax error - */ - function assertThrowsQuiet(var_args) { - silenceFailureLogging(); - assertThrows.apply(null, arguments); - unsilenceFailureLogging(); - } - - // Most of the basic functionality is tested in strictmock_test; these tests - // cover the cases where loose mocks are different from strict mocks - function testSimpleExpectations() { - mock.a(5); - mock.b(); - mock.$replay(); - mock.a(5); - mock.b(); - mock.$verify(); - - mock.$reset(); - - mock.a(); - mock.b(); - mock.$replay(); - mock.b(); - mock.a(); - mock.$verify(); - - mock.$reset(); - - mock.a(5).$times(2); - mock.a(5); - mock.a(2); - mock.$replay(); - mock.a(5); - mock.a(5); - mock.a(5); - mock.a(2); - mock.$verify(); - } - - - function testMultipleExpectations() { - mock.a().$returns(1); - mock.a().$returns(2); - mock.$replay(); - assertEquals(1, mock.a()); - assertEquals(2, mock.a()); - mock.$verify(); - } - - - function testMultipleExpectationArgs() { - mock.a('asdf').$anyTimes(); - mock.a('qwer').$anyTimes(); - mock.b().$times(3); - mock.$replay(); - mock.a('asdf'); - mock.b(); - mock.a('asdf'); - mock.a('qwer'); - mock.b(); - mock.a('qwer'); - mock.b(); - mock.$verify(); - - mock.$reset(); - - mock.a('asdf').$anyTimes(); - mock.a('qwer').$anyTimes(); - mock.$replay(); - mock.a('asdf'); - mock.a('qwer'); - goog.bind(mock.a, mock, 'asdf'); - goog.bind(mock.$verify, mock); - } - - function testSameMethodOutOfOrder() { - mock.a('foo').$returns(1); - mock.a('bar').$returns(2); - mock.$replay(); - assertEquals(2, mock.a('bar')); - assertEquals(1, mock.a('foo')); - } - - function testSameMethodDifferentReturnValues() { - mock.a('foo').$returns(1).$times(2); - mock.a('foo').$returns(3); - mock.a('bar').$returns(2); - mock.$replay(); - assertEquals(1, mock.a('foo')); - assertEquals(2, mock.a('bar')); - assertEquals(1, mock.a('foo')); - assertEquals(3, mock.a('foo')); - assertThrowsQuiet(function() { - mock.a('foo'); - mock.$verify(); - }); - } - - function testSameMethodBrokenExpectations() { - // This is a weird corner case. - // No way to ever make this verify no matter what you call after replaying, - // because the second expectation of mock.a('foo') will be masked by - // the first expectation that can be called any number of times, and so we - // can never satisfy that second expectation. - mock.a('foo').$returns(1).$anyTimes(); - mock.a('bar').$returns(2); - mock.a('foo').$returns(3); - - // LooseMock can detect this case and fail on $replay. - assertThrowsQuiet(goog.bind(mock.$replay, mock)); - mock.$reset(); - - // This is a variant of the corner case above, but it's harder to determine - // that the expectation to mock.a('bar') can never be satisfied. So we don't - // fail on $replay, but we do fail on $verify. - mock.a(goog.testing.mockmatchers.isString).$returns(1).$anyTimes(); - mock.a('bar').$returns(2); - mock.$replay(); - - assertEquals(1, mock.a('foo')); - assertEquals(1, mock.a('bar')); - assertThrowsQuiet(goog.bind(mock.$verify, mock)); - } - - function testSameMethodMultipleAnyTimes() { - mock.a('foo').$returns(1).$anyTimes(); - mock.a('foo').$returns(2).$anyTimes(); - mock.$replay(); - assertEquals(1, mock.a('foo')); - assertEquals(1, mock.a('foo')); - assertEquals(1, mock.a('foo')); - // Note we'll never return 2 but that's ok. - mock.$verify(); - } - - function testFailingFast() { - mock.a().$anyTimes(); - mock.$replay(); - mock.a(); - mock.a(); - assertThrowsQuiet(goog.bind(mock.b, mock)); - mock.$reset(); - - // too many - mock.a(); - mock.b(); - mock.$replay(); - mock.a(); - mock.b(); - - var message; - silenceFailureLogging(); - try { - mock.a(); - } catch (e) { - message = e.message; - } - unsilenceFailureLogging(); - - assertTrue('No exception thrown on unexpected call', goog.isDef(message)); - assertContains('Too many calls to a', message); - } - - function testTimes() { - mock.a().$times(3); - mock.b().$times(2); - mock.$replay(); - mock.a(); - mock.b(); - mock.b(); - mock.a(); - mock.a(); - mock.$verify(); - } - - - function testFailingSlow() { - // not enough - mock.a().$times(3); - mock.$replay(); - mock.a(); - mock.a(); - assertThrowsQuiet(goog.bind(mock.$verify, mock)); - - mock.$reset(); - - // not enough, interleaved order - mock.a().$times(3); - mock.b().$times(3); - mock.$replay(); - mock.a(); - mock.b(); - mock.a(); - mock.b(); - assertThrowsQuiet(goog.bind(mock.$verify, mock)); - - mock.$reset(); - // bad args - mock.a('asdf').$anyTimes(); - mock.$replay(); - mock.a('asdf'); - assertThrowsQuiet(goog.bind(mock.a, mock, 'qwert')); - assertThrowsQuiet(goog.bind(mock.$verify, mock)); - } - - - function testArgsAndReturns() { - mock.a('asdf').$atLeastOnce().$returns(5); - mock.b('qwer').$times(2).$returns(3); - mock.$replay(); - assertEquals(5, mock.a('asdf')); - assertEquals(3, mock.b('qwer')); - assertEquals(5, mock.a('asdf')); - assertEquals(5, mock.a('asdf')); - assertEquals(3, mock.b('qwer')); - mock.$verify(); - } - - - function testThrows() { - mock.a().$throws('exception!'); - mock.$replay(); - assertThrowsQuiet(goog.bind(mock.a, mock)); - mock.$verify(); - } - - - function testDoes() { - mock.a(1, 2).$does(function(a, b) {return a + b;}); - mock.$replay(); - assertEquals('Mock should call the function', 3, mock.a(1, 2)); - mock.$verify(); - } - - function testIgnoresExtraCalls() { - mock = new goog.testing.LooseMock(RealObject, true); - mock.a(); - mock.$replay(); - mock.a(); - mock.b(); // doesn't throw - mock.$verify(); - } - - function testSkipAnyTimes() { - mock = new goog.testing.LooseMock(RealObject); - mock.a(1).$anyTimes(); - mock.a(2).$anyTimes(); - mock.a(3).$anyTimes(); - mock.$replay(); - mock.a(1); - mock.a(3); - mock.$verify(); - } - - function testErrorMessageForBadArgs() { - mock.a(); - mock.$anyTimes(); - - mock.$replay(); - - var message; - silenceFailureLogging(); - try { - mock.a('a'); - } catch (e) { - message = e.message; - } - unsilenceFailureLogging(); - - assertTrue('No exception thrown on verify', goog.isDef(message)); - assertContains('Bad arguments to a()', message); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mock.js.svn-base deleted file mode 100644 index 2312cc5..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mock.js.svn-base +++ /dev/null @@ -1,579 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview This file defines base classes used for creating mocks in - * JavaScript. The API was inspired by EasyMock. - * - * The basic API is: - * <ul> - * <li>Create an object to be mocked - * <li>Create a mock object, passing in the above object to the constructor - * <li>Set expectations by calling methods on the mock object - * <li>Call $replay() on the mock object - * <li>Pass the mock to code that will make real calls on it - * <li>Call $verify() to make sure that expectations were met - * </ul> - * - * For examples, please see the unit tests for LooseMock and StrictMock. - * - * Still TODO - * implement better (and pluggable) argument matching - * Have the exceptions for LooseMock show the number of expected/actual calls - * loose and strict mocks share a lot of code - move it to the base class - * - */ - -goog.provide('goog.testing.Mock'); -goog.provide('goog.testing.MockExpectation'); - -goog.require('goog.array'); -goog.require('goog.testing.JsUnitException'); -goog.require('goog.testing.MockInterface'); -goog.require('goog.testing.mockmatchers'); - - - -/** - * This is a class that represents an expectation. - * @param {string} name The name of the method for this expectation. - * @constructor - */ -goog.testing.MockExpectation = function(name) { - /** - * The name of the method that is expected to be called. - * @type {string} - */ - this.name = name; - - /** - * An array of error messages for expectations not met. - * @type {Array} - */ - this.errorMessages = []; -}; - - -/** - * The minimum number of times this method should be called. - * @type {number} - */ -goog.testing.MockExpectation.prototype.minCalls = 1; - - -/** - * The maximum number of times this method should be called. - * @type {number} - */ -goog.testing.MockExpectation.prototype.maxCalls = 1; - - -/** - * The value that this method should return. - * @type {*} - */ -goog.testing.MockExpectation.prototype.returnValue; - - -/** - * The value that will be thrown when the method is called - * @type {*} - */ -goog.testing.MockExpectation.prototype.exceptionToThrow; - - -/** - * The arguments that are expected to be passed to this function - * @type {Array.<*>} - */ -goog.testing.MockExpectation.prototype.argumentList; - - -/** - * The number of times this method is called by real code. - * @type {number} - */ -goog.testing.MockExpectation.prototype.actualCalls = 0; - - -/** - * The number of times this method is called during the verification phase. - * @type {number} - */ -goog.testing.MockExpectation.prototype.verificationCalls = 0; - - -/** - * The function which will be executed when this method is called. - * Method arguments will be passed to this function, and return value - * of this function will be returned by the method. - * @type {Function} - */ -goog.testing.MockExpectation.prototype.toDo; - - -/** - * Allow expectation failures to include messages. - * @param {string} message The failure message. - */ -goog.testing.MockExpectation.prototype.addErrorMessage = function(message) { - this.errorMessages.push(message); -}; - - -/** - * Get the error messages seen so far. - * @return {string} Error messages separated by \n. - */ -goog.testing.MockExpectation.prototype.getErrorMessage = function() { - return this.errorMessages.join('\n'); -}; - - -/** - * Get how many error messages have been seen so far. - * @return {number} Count of error messages. - */ -goog.testing.MockExpectation.prototype.getErrorMessageCount = function() { - return this.errorMessages.length; -}; - - - -/** - * The base class for a mock object. - * @param {Object|Function} objectToMock The object that should be mocked, or - * the constructor of an object to mock. - * @param {boolean=} opt_mockStaticMethods An optional argument denoting that - * a mock should be constructed from the static functions of a class. - * @param {boolean=} opt_createProxy An optional argument denoting that - * a proxy for the target mock should be created. - * @constructor - * @implements {goog.testing.MockInterface} - */ -goog.testing.Mock = function(objectToMock, opt_mockStaticMethods, - opt_createProxy) { - if (!goog.isObject(objectToMock) && !goog.isFunction(objectToMock)) { - throw new Error('objectToMock must be an object or constructor.'); - } - if (opt_createProxy && !opt_mockStaticMethods && - goog.isFunction(objectToMock)) { - /** @constructor */ - function tempCtor() {}; - goog.inherits(tempCtor, objectToMock); - this.$proxy = new tempCtor(); - } else if (opt_createProxy && opt_mockStaticMethods && - goog.isFunction(objectToMock)) { - throw Error('Cannot create a proxy when opt_mockStaticMethods is true'); - } else if (opt_createProxy && !goog.isFunction(objectToMock)) { - throw Error('Must have a constructor to create a proxy'); - } - - if (goog.isFunction(objectToMock) && !opt_mockStaticMethods) { - this.$initializeFunctions_(objectToMock.prototype); - } else { - this.$initializeFunctions_(objectToMock); - } - this.$argumentListVerifiers_ = {}; -}; - - -/** - * Option that may be passed when constructing function, method, and - * constructor mocks. Indicates that the expected calls should be accepted in - * any order. - * @const - * @type {number} - */ -goog.testing.Mock.LOOSE = 1; - - -/** - * Option that may be passed when constructing function, method, and - * constructor mocks. Indicates that the expected calls should be accepted in - * the recorded order only. - * @const - * @type {number} - */ -goog.testing.Mock.STRICT = 0; - - -/** - * A proxy for the mock. This can be used for dependency injection in lieu of - * the mock if the test requires a strict instanceof check. - * @type {Object} - */ -goog.testing.Mock.prototype.$proxy = null; - - -/** - * Map of argument name to optional argument list verifier function. - * @type {Object} - */ -goog.testing.Mock.prototype.$argumentListVerifiers_; - - -/** - * Whether or not we are in recording mode. - * @type {boolean} - * @private - */ -goog.testing.Mock.prototype.$recording_ = true; - - -/** - * The expectation currently being created. All methods that modify the - * current expectation return the Mock object for easy chaining, so this is - * where we keep track of the expectation that's currently being modified. - * @type {goog.testing.MockExpectation} - * @protected - */ -goog.testing.Mock.prototype.$pendingExpectation; - - -/** - * First exception thrown by this mock; used in $verify. - * @type {Object} - * @private - */ -goog.testing.Mock.prototype.$threwException_ = null; - - -/** - * Initializes the functions on the mock object. - * @param {Object} objectToMock The object being mocked. - * @private - */ -goog.testing.Mock.prototype.$initializeFunctions_ = function(objectToMock) { - // TODO (arv): Implement goog.object.getIterator and replace this loop. - for (var prop in objectToMock) { - if (typeof objectToMock[prop] == 'function') { - this[prop] = goog.bind(this.$mockMethod, this, prop); - if (this.$proxy) { - this.$proxy[prop] = goog.bind(this.$mockMethod, this, prop); - } - } - } -}; - - -/** - * Registers a verfifier function to use when verifying method argument lists. - * @param {string} methodName The name of the method for which the verifierFn - * should be used. - * @param {Function} fn Argument list verifier function. Should take 2 argument - * arrays as arguments, and return true if they are considered equivalent. - * @return {goog.testing.Mock} This mock object. - */ -goog.testing.Mock.prototype.$registerArgumentListVerifier = function(methodName, - fn) { - this.$argumentListVerifiers_[methodName] = fn; - return this; -}; - - -/** - * The function that replaces all methods on the mock object. - * @param {string} name The name of the method being mocked. - * @return {*} In record mode, returns the mock object. In replay mode, returns - * whatever the creator of the mock set as the return value. - */ -goog.testing.Mock.prototype.$mockMethod = function(name) { - try { - // Shift off the name argument so that args contains the arguments to - // the mocked method. - var args = goog.array.slice(arguments, 1); - if (this.$recording_) { - this.$pendingExpectation = new goog.testing.MockExpectation(name); - this.$pendingExpectation.argumentList = args; - this.$recordExpectation(); - return this; - } else { - return this.$recordCall(name, args); - } - } catch (ex) { - this.$recordAndThrow(ex); - } -}; - - -/** - * Records the currently pending expectation, intended to be overridden by a - * subclass. - * @protected - */ -goog.testing.Mock.prototype.$recordExpectation = function() {}; - - -/** - * Records an actual method call, intended to be overridden by a - * subclass. The subclass must find the pending expectation and return the - * correct value. - * @param {string} name The name of the method being called. - * @param {Array} args The arguments to the method. - * @return {*} The return expected by the mock. - * @protected - */ -goog.testing.Mock.prototype.$recordCall = function(name, args) { - return undefined; -}; - - -/** - * If the expectation expects to throw, this method will throw. - * @param {goog.testing.MockExpectation} expectation The expectation. - */ -goog.testing.Mock.prototype.$maybeThrow = function(expectation) { - if (typeof expectation.exceptionToThrow != 'undefined') { - throw expectation.exceptionToThrow; - } -}; - - -/** - * If this expectation defines a function to be called, - * it will be called and its result will be returned. - * Otherwise, if the expectation expects to throw, it will throw. - * Otherwise, this method will return defined value. - * @param {goog.testing.MockExpectation} expectation The expectation. - * @param {Array} args The arguments to the method. - * @return {*} The return value expected by the mock. - */ -goog.testing.Mock.prototype.$do = function(expectation, args) { - if (typeof expectation.toDo == 'undefined') { - this.$maybeThrow(expectation); - return expectation.returnValue; - } else { - return expectation.toDo.apply(this, args); - } -}; - - -/** - * Specifies a return value for the currently pending expectation. - * @param {*} val The return value. - * @return {goog.testing.Mock} This mock object. - */ -goog.testing.Mock.prototype.$returns = function(val) { - this.$pendingExpectation.returnValue = val; - return this; -}; - - -/** - * Specifies a value for the currently pending expectation to throw. - * @param {*} val The value to throw. - * @return {goog.testing.Mock} This mock object. - */ -goog.testing.Mock.prototype.$throws = function(val) { - this.$pendingExpectation.exceptionToThrow = val; - return this; -}; - - -/** - * Specifies a function to call for currently pending expectation. - * Note, that using this method overrides declarations made - * using $returns() and $throws() methods. - * @param {Function} func The function to call. - * @return {goog.testing.Mock} This mock object. - */ -goog.testing.Mock.prototype.$does = function(func) { - this.$pendingExpectation.toDo = func; - return this; -}; - - -/** - * Allows the expectation to be called 0 or 1 times. - * @return {goog.testing.Mock} This mock object. - */ -goog.testing.Mock.prototype.$atMostOnce = function() { - this.$pendingExpectation.minCalls = 0; - this.$pendingExpectation.maxCalls = 1; - return this; -}; - - -/** - * Allows the expectation to be called any number of times, as long as it's - * called once. - * @return {goog.testing.Mock} This mock object. - */ -goog.testing.Mock.prototype.$atLeastOnce = function() { - this.$pendingExpectation.maxCalls = Infinity; - return this; -}; - - -/** - * Allows the expectation to be called any number of times. - * @return {goog.testing.Mock} This mock object. - */ -goog.testing.Mock.prototype.$anyTimes = function() { - this.$pendingExpectation.minCalls = 0; - this.$pendingExpectation.maxCalls = Infinity; - return this; -}; - - -/** - * Specifies the number of times the expectation should be called. - * @param {number} times The number of times this method will be called. - * @return {goog.testing.Mock} This mock object. - */ -goog.testing.Mock.prototype.$times = function(times) { - this.$pendingExpectation.minCalls = times; - this.$pendingExpectation.maxCalls = times; - return this; -}; - - -/** - * Switches from recording to replay mode. - */ -goog.testing.Mock.prototype.$replay = function() { - this.$recording_ = false; -}; - - -/** - * Resets the state of this mock object. This clears all pending expectations - * without verifying, and puts the mock in recording mode. - */ -goog.testing.Mock.prototype.$reset = function() { - this.$recording_ = true; - this.$threwException_ = null; - delete this.$pendingExpectation; -}; - - -/** - * Throws an exception and records that an exception was thrown. - * @param {string} comment A short comment about the exception. - * @param {?string=} opt_message A longer message about the exception. - * @throws {Object} JsUnitException object. - * @protected - */ -goog.testing.Mock.prototype.$throwException = function(comment, opt_message) { - this.$recordAndThrow(new goog.testing.JsUnitException(comment, opt_message)); -}; - - -/** - * Throws an exception and records that an exception was thrown. - * @param {Object} ex Exception. - * @throws {Object} #ex. - * @protected - */ -goog.testing.Mock.prototype.$recordAndThrow = function(ex) { - // If it's an assert exception, record it. - if (ex['isJsUnitException']) { - var testRunner = goog.global['G_testRunner']; - if (testRunner) { - var logTestFailureFunction = testRunner['logTestFailure']; - if (logTestFailureFunction) { - logTestFailureFunction.call(testRunner, ex); - } - } - - if (!this.$threwException_) { - // Only remember first exception thrown. - this.$threwException_ = ex; - } - } - throw ex; -}; - - -/** - * Verify that all of the expectations were met. Should be overridden by - * subclasses. - */ -goog.testing.Mock.prototype.$verify = function() { - if (this.$threwException_) { - throw this.$threwException_; - } -}; - - -/** - * Verifies that a method call matches an expectation. - * @param {goog.testing.MockExpectation} expectation The expectation to check. - * @param {string} name The name of the called method. - * @param {Array.<*>?} args The arguments passed to the mock. - * @return {boolean} Whether the call matches the expectation. - */ -goog.testing.Mock.prototype.$verifyCall = function(expectation, name, args) { - if (expectation.name != name) { - return false; - } - var verifierFn = - this.$argumentListVerifiers_.hasOwnProperty(expectation.name) ? - this.$argumentListVerifiers_[expectation.name] : - goog.testing.mockmatchers.flexibleArrayMatcher; - - return verifierFn(expectation.argumentList, args, expectation); -}; - - -/** - * Render the provided argument array to a string to help - * clients with debugging tests. - * @param {Array.<*>?} args The arguments passed to the mock. - * @return {string} Human-readable string. - */ -goog.testing.Mock.prototype.$argumentsAsString = function(args) { - var retVal = []; - for (var i = 0; i < args.length; i++) { - try { - retVal.push(goog.typeOf(args[i])); - } catch (e) { - retVal.push('[unknown]'); - } - } - return '(' + retVal.join(', ') + ')'; -}; - - -/** - * Throw an exception based on an incorrect method call. - * @param {string} name Name of method called. - * @param {Array.<*>?} args Arguments passed to the mock. - * @param {goog.testing.MockExpectation=} opt_expectation Expected next call, - * if any. - */ -goog.testing.Mock.prototype.$throwCallException = function(name, args, - opt_expectation) { - var errorStringBuffer = []; - var actualArgsString = this.$argumentsAsString(args); - var expectedArgsString = opt_expectation ? - this.$argumentsAsString(opt_expectation.argumentList) : ''; - - if (opt_expectation && opt_expectation.name == name) { - errorStringBuffer.push('Bad arguments to ', name, '().\n', - 'Actual: ', actualArgsString, '\n', - 'Expected: ', expectedArgsString, '\n', - opt_expectation.getErrorMessage()); - } else { - errorStringBuffer.push('Unexpected call to ', name, - actualArgsString, '.'); - if (opt_expectation) { - errorStringBuffer.push('\nNext expected call was to ', - opt_expectation.name, - expectedArgsString); - } - } - this.$throwException(errorStringBuffer.join('')); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mock_test.html.svn-base deleted file mode 100644 index be592a6..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mock_test.html.svn-base +++ /dev/null @@ -1,213 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.Mock</title> -<script src="../base.js"></script> -<script> - goog.require('goog.array'); - goog.require('goog.object'); - goog.require('goog.testing.Mock'); - goog.require('goog.testing.MockExpectation'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - - // The object that we will be mocking - var RealObject = function() { - }; - - RealObject.prototype.a = function() { - fail('real object should never be called'); - }; - - RealObject.prototype.b = function() { - fail('real object should never be called'); - }; - - var matchers = goog.testing.mockmatchers; - var mock; - - function setUp() { - var obj = new RealObject(); - mock = new goog.testing.Mock(obj); - } - - function testMockErrorMessage() { - var expectation = new goog.testing.MockExpectation('a'); - assertEquals(0, expectation.getErrorMessageCount()); - assertEquals('', expectation.getErrorMessage()); - - expectation.addErrorMessage('foo failed'); - assertEquals(1, expectation.getErrorMessageCount()); - assertEquals('foo failed', expectation.getErrorMessage()); - - expectation.addErrorMessage('bar failed'); - assertEquals(2, expectation.getErrorMessageCount()); - assertEquals('foo failed\nbar failed', expectation.getErrorMessage()); - } - - function testVerifyArgumentList() { - var expectation = new goog.testing.MockExpectation('a'); - assertEquals('', expectation.getErrorMessage()); - - // test single string arg - expectation.argumentList = ['foo']; - assertTrue(mock.$verifyCall(expectation, 'a', ['foo'])); - - // single numeric arg - expectation.argumentList = [2] - assertTrue(mock.$verifyCall(expectation, 'a', [2])); - - // single object arg (using standard === comparison) - var obj = {prop1: 'prop1', prop2: 2}; - expectation.argumentList = [obj]; - assertTrue(mock.$verifyCall(expectation, 'a', [obj])); - - // make sure comparison succeeds if args are similar, but not === - var obj2 = {prop1: 'prop1', prop2: 2}; - expectation.argumentList = [obj]; - assertTrue(mock.$verifyCall(expectation, 'a', [obj2])); - assertEquals('', expectation.getErrorMessage()); - - // multiple args - expectation.argumentList = ['foo', 2, obj, obj2]; - assertTrue(mock.$verifyCall(expectation, 'a', ['foo', 2, obj, obj2])); - - // test flexible arg matching. - expectation.argumentList = ['foo', matchers.isNumber]; - assertTrue(mock.$verifyCall(expectation, 'a', ['foo', 1])); - - expectation.argumentList = [new matchers.InstanceOf(RealObject)]; - assertTrue(mock.$verifyCall(expectation, 'a', [new RealObject()])); - } - - function testVerifyArgumentListForObjectMethods() { - var expectation = new goog.testing.MockExpectation('toString'); - expectation.argumentList = [] - assertTrue(mock.$verifyCall(expectation, 'toString', [])); - } - - function testRegisterArgumentListVerifier() { - var expectationA = new goog.testing.MockExpectation('a'); - var expectationB = new goog.testing.MockExpectation('b'); - - // Simple matcher that return true if all args are === equivalent. - mock.$registerArgumentListVerifier('a', function(expectedArgs, args) { - return goog.array.equals(expectedArgs, args, function(a, b) { - return (a === b); - }); - }); - - // test single string arg - expectationA.argumentList = ['foo']; - assertTrue(mock.$verifyCall(expectationA, 'a', ['foo'])); - - // single numeric arg - expectationA.argumentList = [2] - assertTrue(mock.$verifyCall(expectationA, 'a', [2])); - - // single object arg (using standard === comparison) - var obj = {prop1: 'prop1', prop2: 2}; - expectationA.argumentList = [obj]; - expectationB.argumentList = [obj]; - assertTrue(mock.$verifyCall(expectationA, 'a', [obj])); - assertTrue(mock.$verifyCall(expectationB, 'b', [obj])); - - // if args are similar, but not ===, then comparison should succeed - // for method with registered object matcher, and fail for method without - var obj2 = {prop1: 'prop1', prop2: 2}; - expectationA.argumentList = [obj]; - expectationB.argumentList = [obj]; - assertFalse(mock.$verifyCall(expectationA, 'a', [obj2])) - assertTrue(mock.$verifyCall(expectationB, 'b', [obj2])); - - - // multiple args, should fail for method with registered arg matcher, - // and succeed for method without. - expectationA.argumentList = ['foo', 2, obj, obj2]; - expectationB.argumentList = ['foo', 2, obj, obj2]; - assertFalse(mock.$verifyCall(expectationA, 'a', ['foo', 2, obj2, obj])); - assertTrue(mock.$verifyCall(expectationB, 'b', ['foo', 2, obj2, obj])); - } - - - function testCreateProxy() { - mock = new goog.testing.Mock(RealObject, false, true); - assertTrue(mock.$proxy instanceof RealObject); - assertThrows(function() { - new goog.testing.Mock(RealObject, true, true); - }); - assertThrows(function() { - new goog.testing.Mock(1, false, true); - }); - } - - - function testValidConstructorArgument() { - var someNamespace = { }; - assertThrows(function() { - new goog.testing.Mock(someNamespace.RealObjectWithTypo); - }); - } - - - function testArgumentsAsString() { - assertEquals('()', mock.$argumentsAsString([])); - assertEquals('(string, number, object, null)', - mock.$argumentsAsString(['red', 1, {}, null])); - } - - - function testThrowCallExceptionBadArgs() { - var msg; - mock.$throwException = function(m) { - msg = m; - }; - - mock.$throwCallException( - 'fn1', [ 'b' ], - { name: 'fn1', - argumentList: [ 'c' ], - getErrorMessage: function() { return ''; } }); - assertContains( - 'Bad arguments to fn1().\nActual: (string)\nExpected: (string)', msg); - } - - function testThrowCallExceptionUnexpected() { - var msg; - mock.$throwException = function(m) { - msg = m; - }; - - mock.$throwCallException('fn1', [ 'b' ]); - assertEquals('Unexpected call to fn1(string).', msg); - } - - function testThrowCallExceptionUnexpectedWithNext() { - var msg; - mock.$throwException = function(m) { - msg = m; - }; - - mock.$throwCallException( - 'fn1', [ 'b' ], - { name: 'fn2', - argumentList: [ 3 ], - getErrorMessage: function() { return ''; } }); - assertEquals( - 'Unexpected call to fn1(string).\n' + - 'Next expected call was to fn2(number)', msg); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclassfactory.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclassfactory.js.svn-base deleted file mode 100644 index 4f71b39..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclassfactory.js.svn-base +++ /dev/null @@ -1,580 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview This file defines a factory that can be used to mock and - * replace an entire class. This allows for mocks to be used effectively with - * "new" instead of having to inject all instances. Essentially, a given class - * is replaced with a proxy to either a loose or strict mock. Proxies locate - * the appropriate mock based on constructor arguments. - * - * The usage is: - * <ul> - * <li>Create a mock with one of the provided methods with a specifc set of - * constructor arguments - * <li>Set expectations by calling methods on the mock object - * <li>Call $replay() on the mock object - * <li>Instantiate the object as normal - * <li>Call $verify() to make sure that expectations were met - * <li>Call reset on the factory to revert all classes back to their original - * state - * </ul> - * - * For examples, please see the unit test. - * - */ - - -goog.provide('goog.testing.MockClassFactory'); -goog.provide('goog.testing.MockClassRecord'); - -goog.require('goog.array'); -goog.require('goog.object'); -goog.require('goog.testing.LooseMock'); -goog.require('goog.testing.StrictMock'); -goog.require('goog.testing.TestCase'); -goog.require('goog.testing.mockmatchers'); - - - -/** - * A record that represents all the data associated with a mock replacement of - * a given class. - * @param {Object} namespace The namespace in which the mocked class resides. - * @param {string} className The name of the class within the namespace. - * @param {Function} originalClass The original class implementation before it - * was replaced by a proxy. - * @param {Function} proxy The proxy that replaced the original class. - * @constructor - */ -goog.testing.MockClassRecord = function(namespace, className, originalClass, - proxy) { - /** - * A standard closure namespace (e.g. goog.foo.bar) that contains the mock - * class referenced by this MockClassRecord. - * @type {Object} - * @private - */ - this.namespace_ = namespace; - - /** - * The name of the class within the provided namespace. - * @type {string} - * @private - */ - this.className_ = className; - - /** - * The original class implementation. - * @type {Function} - * @private - */ - this.originalClass_ = originalClass; - - /** - * The proxy being used as a replacement for the original class. - * @type {Function} - * @private - */ - this.proxy_ = proxy; - - /** - * A mocks that will be constructed by their argument list. The entries are - * objects with the format {'args': args, 'mock': mock}. - * @type {Array.<Object>} - * @private - */ - this.instancesByArgs_ = []; -}; - - -/** - * A mock associated with the static functions for a given class. - * @type {goog.testing.StrictMock|goog.testing.LooseMock|null} - * @private - */ -goog.testing.MockClassRecord.prototype.staticMock_ = null; - - -/** - * A getter for this record's namespace. - * @return {Object} The namespace. - */ -goog.testing.MockClassRecord.prototype.getNamespace = function() { - return this.namespace_; -}; - - -/** - * A getter for this record's class name. - * @return {string} The name of the class referenced by this record. - */ -goog.testing.MockClassRecord.prototype.getClassName = function() { - return this.className_; -}; - - -/** - * A getter for the original class. - * @return {Function} The original class implementation before mocking. - */ -goog.testing.MockClassRecord.prototype.getOriginalClass = function() { - return this.originalClass_; -}; - - -/** - * A getter for the proxy being used as a replacement for the original class. - * @return {Function} The proxy. - */ -goog.testing.MockClassRecord.prototype.getProxy = function() { - return this.proxy_; -}; - - -/** - * A getter for the static mock. - * @return {goog.testing.StrictMock|goog.testing.LooseMock|null} The static - * mock associated with this record. - */ -goog.testing.MockClassRecord.prototype.getStaticMock = function() { - return this.staticMock_; -}; - - -/** - * A setter for the static mock. - * @param {goog.testing.StrictMock|goog.testing.LooseMock} staticMock A mock to - * associate with the static functions for the referenced class. - */ -goog.testing.MockClassRecord.prototype.setStaticMock = function(staticMock) { - this.staticMock_ = staticMock; -}; - - -/** - * Adds a new mock instance mapping. The mapping connects a set of function - * arguments to a specific mock instance. - * @param {Array} args An array of function arguments. - * @param {goog.testing.StrictMock|goog.testing.LooseMock} mock A mock - * associated with the supplied arguments. - */ -goog.testing.MockClassRecord.prototype.addMockInstance = function(args, mock) { - this.instancesByArgs_.push({args: args, mock: mock}); -}; - - -/** - * Finds the mock corresponding to a given argument set. Throws an error if - * there is no appropriate match found. - * @param {Array} args An array of function arguments. - * @return {goog.testing.StrictMock|goog.testing.LooseMock|null} The mock - * corresponding to a given argument set. - */ -goog.testing.MockClassRecord.prototype.findMockInstance = function(args) { - for (var i = 0; i < this.instancesByArgs_.length; i++) { - var instanceArgs = this.instancesByArgs_[i].args; - if (goog.testing.mockmatchers.flexibleArrayMatcher(instanceArgs, args)) { - return this.instancesByArgs_[i].mock; - } - } - - return null; -}; - - -/** - * Resets this record by reverting all the mocked classes back to the original - * implementation and clearing out the mock instance list. - */ -goog.testing.MockClassRecord.prototype.reset = function() { - this.namespace_[this.className_] = this.originalClass_; - this.instancesByArgs_ = []; -}; - - - -/** - * A factory used to create new mock class instances. It is able to generate - * both static and loose mocks. The MockClassFactory is a singleton since it - * tracks the classes that have been mocked internally. - * @constructor - */ -goog.testing.MockClassFactory = function() { - if (goog.testing.MockClassFactory.instance_) { - return goog.testing.MockClassFactory.instance_; - } - - /** - * A map from class name -> goog.testing.MockClassRecord. - * @type {Object} - * @private - */ - this.mockClassRecords_ = {}; - - goog.testing.MockClassFactory.instance_ = this; -}; - - -/** - * A singleton instance of the MockClassFactory. - * @type {goog.testing.MockClassFactory?} - * @private - */ -goog.testing.MockClassFactory.instance_ = null; - - -/** - * The names of the fields that are defined on Object.prototype. - * @type {Array.<string>} - * @private - */ -goog.testing.MockClassFactory.PROTOTYPE_FIELDS_ = [ - 'constructor', - 'hasOwnProperty', - 'isPrototypeOf', - 'propertyIsEnumerable', - 'toLocaleString', - 'toString', - 'valueOf' -]; - - -/** - * Iterates through a namespace to find the name of a given class. This is done - * solely to support compilation since string identifiers would break down. - * Tests usually aren't compiled, but the functionality is supported. - * @param {Object} namespace A javascript namespace (e.g. goog.testing). - * @param {Function} classToMock The class whose name should be returned. - * @return {string} The name of the class. - * @private - */ -goog.testing.MockClassFactory.prototype.getClassName_ = function(namespace, - classToMock) { - if (namespace === goog.global) { - namespace = goog.testing.TestCase.getGlobals(); - } - for (var prop in namespace) { - if (namespace[prop] === classToMock) { - return prop; - } - } - - throw Error('Class is not a part of the given namespace'); -}; - - -/** - * Returns whether or not a given class has been mocked. - * @param {string} className The name of the class. - * @return {boolean} Whether or not the given class name has a MockClassRecord. - * @private - */ -goog.testing.MockClassFactory.prototype.classHasMock_ = function(className) { - return !!this.mockClassRecords_[className]; -}; - - -/** - * Returns a proxy constructor closure. Since this is a constructor, "this" - * refers to the local scope of the constructed object thus bind cannot be - * used. - * @param {string} className The name of the class. - * @param {Function} mockFinder A bound function that returns the mock - * associated with a class given the constructor's argument list. - * @return {Function} A proxy constructor. - * @private - */ -goog.testing.MockClassFactory.prototype.getProxyCtor_ = function(className, - mockFinder) { - return function() { - this.$mock_ = mockFinder(className, arguments); - if (!this.$mock_) { - // The "arguments" variable is not a proper Array so it must be converted. - var args = Array.prototype.slice.call(arguments, 0); - throw Error('No mock found for ' + className + ' with arguments ' + - args.join(', ')); - } - }; -}; - - -/** - * Returns a proxy function for a mock class instance. This function cannot - * be used with bind since "this" must refer to the scope of the proxy - * constructor. - * @param {string} fnName The name of the function that should be proxied. - * @return {Function} A proxy function. - * @private - */ -goog.testing.MockClassFactory.prototype.getProxyFunction_ = function(fnName) { - return function() { - return this.$mock_[fnName].apply(this.$mock_, arguments); - }; -}; - - -/** - * Find a mock instance for a given class name and argument list. - * @param {string} className The name of the class. - * @param {Array} args The argument list to match. - * @return {goog.testing.StrictMock|goog.testing.LooseMock} The mock found for - * the given argument list. - * @private - */ -goog.testing.MockClassFactory.prototype.findMockInstance_ = function(className, - args) { - return this.mockClassRecords_[className].findMockInstance(args); -}; - - -/** - * Create a proxy class. A proxy will pass functions to the mock for a class. - * The proxy class only covers prototype methods. A static mock is not build - * simultaneously since it might be strict or loose. The proxy class inherits - * from the target class in order to preserve instanceof checks. - * @param {Object} namespace A javascript namespace (e.g. goog.testing). - * @param {Function} classToMock The class that will be proxied. - * @param {string} className The name of the class. - * @return {Function} The proxy for provided class. - * @private - */ -goog.testing.MockClassFactory.prototype.createProxy_ = function(namespace, - classToMock, className) { - var proxy = this.getProxyCtor_(className, - goog.bind(this.findMockInstance_, this)); - var protoToProxy = classToMock.prototype; - goog.inherits(proxy, classToMock); - - for (var prop in protoToProxy) { - if (goog.isFunction(protoToProxy[prop])) { - proxy.prototype[prop] = this.getProxyFunction_(prop); - } - } - - // For IE the for-in-loop does not contain any properties that are not - // enumerable on the prototype object (for example isPrototypeOf from - // Object.prototype) and it will also not include 'replace' on objects that - // extend String and change 'replace' (not that it is common for anyone to - // extend anything except Object). - // TODO (arv): Implement goog.object.getIterator and replace this loop. - - goog.array.forEach(goog.testing.MockClassFactory.PROTOTYPE_FIELDS_, - function(field) { - if (Object.prototype.hasOwnProperty.call(protoToProxy, field)) { - proxy.prototype[field] = this.getProxyFunction_(field); - } - }, this); - - this.mockClassRecords_[className] = new goog.testing.MockClassRecord( - namespace, className, classToMock, proxy); - namespace[className] = proxy; - return proxy; -}; - - -/** - * Gets either a loose or strict mock for a given class based on a set of - * arguments. - * @param {Object} namespace A javascript namespace (e.g. goog.testing). - * @param {Function} classToMock The class that will be mocked. - * @param {boolean} isStrict Whether or not the mock should be strict. - * @param {Array} ctorArgs The arguments associated with this instance's - * constructor. - * @return {goog.testing.StrictMock|goog.testing.LooseMock} The mock created - * for the provided class. - * @private - */ -goog.testing.MockClassFactory.prototype.getMockClass_ = - function(namespace, classToMock, isStrict, ctorArgs) { - var className = this.getClassName_(namespace, classToMock); - - // The namespace and classToMock variables should be removed from the - // passed in argument stack. - ctorArgs = goog.array.slice(ctorArgs, 2); - - if (goog.isFunction(classToMock)) { - var mock = isStrict ? new goog.testing.StrictMock(classToMock) : - new goog.testing.LooseMock(classToMock); - - if (!this.classHasMock_(className)) { - this.createProxy_(namespace, classToMock, className); - } else { - var instance = this.findMockInstance_(className, ctorArgs); - if (instance) { - throw Error('Mock instance already created for ' + className + - ' with arguments ' + ctorArgs.join(', ')); - } - } - this.mockClassRecords_[className].addMockInstance(ctorArgs, mock); - - return mock; - } else { - throw Error('Cannot create a mock class for ' + className + - ' of type ' + typeof classToMock); - } -}; - - -/** - * Gets a strict mock for a given class. - * @param {Object} namespace A javascript namespace (e.g. goog.testing). - * @param {Function} classToMock The class that will be mocked. - * @param {...*} var_args The arguments associated with this instance's - * constructor. - * @return {goog.testing.StrictMock} The mock created for the provided class. - */ -goog.testing.MockClassFactory.prototype.getStrictMockClass = - function(namespace, classToMock, var_args) { - var args = /** @type {Array} */ (arguments); - return /** @type {goog.testing.StrictMock} */ (this.getMockClass_(namespace, - classToMock, true, args)); -}; - - -/** - * Gets a loose mock for a given class. - * @param {Object} namespace A javascript namespace (e.g. goog.testing). - * @param {Function} classToMock The class that will be mocked. - * @param {...*} var_args The arguments associated with this instance's - * constructor. - * @return {goog.testing.LooseMock} The mock created for the provided class. - */ -goog.testing.MockClassFactory.prototype.getLooseMockClass = - function(namespace, classToMock, var_args) { - var args = /** @type {Array} */ (arguments); - return /** @type {goog.testing.LooseMock} */ (this.getMockClass_(namespace, - classToMock, false, args)); -}; - - -/** - * Creates either a loose or strict mock for the static functions of a given - * class. - * @param {Function} classToMock The class whose static functions will be - * mocked. This should be the original class and not the proxy. - * @param {string} className The name of the class. - * @param {Function} proxy The proxy that will replace the original class. - * @param {boolean} isStrict Whether or not the mock should be strict. - * @return {goog.testing.StrictMock|goog.testing.LooseMock} The mock created - * for the static functions of the provided class. - * @private - */ -goog.testing.MockClassFactory.prototype.createStaticMock_ = - function(classToMock, className, proxy, isStrict) { - var mock = isStrict ? new goog.testing.StrictMock(classToMock, true) : - new goog.testing.LooseMock(classToMock, false, true); - - for (var prop in classToMock) { - if (goog.isFunction(classToMock[prop])) { - proxy[prop] = goog.bind(mock.$mockMethod, mock, prop); - } else if (classToMock[prop] !== classToMock.prototype) { - proxy[prop] = classToMock[prop]; - } - } - - this.mockClassRecords_[className].setStaticMock(mock); - return mock; -}; - - -/** - * Gets either a loose or strict mock for the static functions of a given class. - * @param {Object} namespace A javascript namespace (e.g. goog.testing). - * @param {Function} classToMock The class whose static functions will be - * mocked. This should be the original class and not the proxy. - * @param {boolean} isStrict Whether or not the mock should be strict. - * @return {goog.testing.StrictMock|goog.testing.LooseMock} The mock created - * for the static functions of the provided class. - * @private - */ -goog.testing.MockClassFactory.prototype.getStaticMock_ = function(namespace, - classToMock, isStrict) { - var className = this.getClassName_(namespace, classToMock); - - if (goog.isFunction(classToMock)) { - if (!this.classHasMock_(className)) { - var proxy = this.createProxy_(namespace, classToMock, className); - var mock = this.createStaticMock_(classToMock, className, proxy, - isStrict); - return mock; - } - - if (!this.mockClassRecords_[className].getStaticMock()) { - var proxy = this.mockClassRecords_[className].getProxy(); - var originalClass = this.mockClassRecords_[className].getOriginalClass(); - var mock = this.createStaticMock_(originalClass, className, proxy, - isStrict); - return mock; - } else { - var mock = this.mockClassRecords_[className].getStaticMock(); - var mockIsStrict = mock instanceof goog.testing.StrictMock; - - if (mockIsStrict != isStrict) { - var mockType = mock instanceof goog.testing.StrictMock ? 'strict' : - 'loose'; - var requestedType = isStrict ? 'strict' : 'loose'; - throw Error('Requested a ' + requestedType + ' static mock, but a ' + - mockType + ' mock already exists.'); - } - - return mock; - } - } else { - throw Error('Cannot create a mock for the static functions of ' + - className + ' of type ' + typeof classToMock); - } -}; - - -/** - * Gets a strict mock for the static functions of a given class. - * @param {Object} namespace A javascript namespace (e.g. goog.testing). - * @param {Function} classToMock The class whose static functions will be - * mocked. This should be the original class and not the proxy. - * @return {goog.testing.StrictMock} The mock created for the static functions - * of the provided class. - */ -goog.testing.MockClassFactory.prototype.getStrictStaticMock = - function(namespace, classToMock) { - return /** @type {goog.testing.StrictMock} */ (this.getStaticMock_(namespace, - classToMock, true)); -}; - - -/** - * Gets a loose mock for the static functions of a given class. - * @param {Object} namespace A javascript namespace (e.g. goog.testing). - * @param {Function} classToMock The class whose static functions will be - * mocked. This should be the original class and not the proxy. - * @return {goog.testing.LooseMock} The mock created for the static functions - * of the provided class. - */ -goog.testing.MockClassFactory.prototype.getLooseStaticMock = - function(namespace, classToMock) { - return /** @type {goog.testing.LooseMock} */ (this.getStaticMock_(namespace, - classToMock, false)); -}; - - -/** - * Resests the factory by reverting all mocked classes to their original - * implementations and removing all MockClassRecords. - */ -goog.testing.MockClassFactory.prototype.reset = function() { - goog.object.forEach(this.mockClassRecords_, function(record) { - record.reset(); - }); - this.mockClassRecords_ = {}; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclassfactory_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclassfactory_test.html.svn-base deleted file mode 100644 index ba6d0f8..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclassfactory_test.html.svn-base +++ /dev/null @@ -1,241 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.MockClassFactory</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.MockClassFactory'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - goog.provide('fake.BaseClass'); - goog.provide('fake.ChildClass'); - - // Classes that will be mocked. A base class and child class are used to - // test inheritance. - fake.BaseClass = function(a) { - fail('real object should never be called'); - }; - - fake.BaseClass.prototype.foo = function() { - fail('real object should never be called'); - }; - - fake.BaseClass.prototype.toString = function() {return 'foo';} - - fake.BaseClass.prototype.toLocaleString = function() {return 'bar';} - - fake.ChildClass = function(a) { - fail('real object should never be called'); - }; - goog.inherits(fake.ChildClass, fake.BaseClass); - - fake.ChildClass.staticFoo = function() { - fail('real object should never be called'); - }; - - fake.ChildClass.prototype.bar = function() { - fail('real object should never be called'); - }; - - fake.ChildClass.staticProperty = 'staticPropertyOnClass'; - - function TopLevelBaseClass() { - } - - var mockClassFactory = new goog.testing.MockClassFactory(); - var matchers = goog.testing.mockmatchers; - - function tearDown() { - mockClassFactory.reset(); - }; - - function testGetStrictMockClass() { - var mock1 = mockClassFactory.getStrictMockClass(fake, fake.BaseClass, 1); - mock1.foo(); - mock1.$replay(); - - var mock2 = mockClassFactory.getStrictMockClass(fake, fake.BaseClass, 2); - mock2.foo(); - mock2.$replay(); - - var mock3 = mockClassFactory.getStrictMockClass(fake, fake.ChildClass, 3); - mock3.foo(); - mock3.bar(); - mock3.$replay(); - - var instance1 = new fake.BaseClass(1); - instance1.foo(); - mock1.$verify(); - - var instance2 = new fake.BaseClass(2); - instance2.foo(); - mock2.$verify(); - - var instance3 = new fake.ChildClass(3); - instance3.foo(); - instance3.bar(); - mock3.$verify(); - - assertThrows(function() {new fake.BaseClass(-1)}); - assertTrue(instance1 instanceof fake.BaseClass); - assertTrue(instance2 instanceof fake.BaseClass); - assertTrue(instance3 instanceof fake.ChildClass); - }; - - function testGetStrictMockClassCreatesAllProxies() { - var mock1 = mockClassFactory.getStrictMockClass(fake, fake.BaseClass, 1); - // toString(), toLocaleString() and others are treaded specially in - // createProxy_(). - mock1.toString(); - mock1.toLocaleString(); - mock1.$replay(); - - var instance1 = new fake.BaseClass(1); - instance1.toString(); - instance1.toLocaleString(); - mock1.$verify(); - } - - function testGetLooseMockClass() { - var mock1 = mockClassFactory.getLooseMockClass(fake, fake.BaseClass, 1); - mock1.foo().$anyTimes().$returns(3); - mock1.$replay(); - - var mock2 = mockClassFactory.getLooseMockClass(fake, fake.BaseClass, 2); - mock2.foo().$times(3); - mock2.$replay(); - - var mock3 = mockClassFactory.getLooseMockClass(fake, fake.ChildClass, 3); - mock3.foo().$atLeastOnce().$returns(5); - mock3.bar().$atLeastOnce(); - mock3.$replay(); - - var instance1 = new fake.BaseClass(1); - assertEquals(3, instance1.foo()); - assertEquals(3, instance1.foo()); - assertEquals(3, instance1.foo()); - assertEquals(3, instance1.foo()); - assertEquals(3, instance1.foo()); - mock1.$verify(); - - var instance2 = new fake.BaseClass(2); - instance2.foo(); - instance2.foo(); - instance2.foo(); - mock2.$verify(); - - var instance3 = new fake.ChildClass(3); - assertEquals(5, instance3.foo()); - assertEquals(5, instance3.foo()); - instance3.bar(); - mock3.$verify(); - - assertThrows(function() {new fake.BaseClass(-1)}); - assertTrue(instance1 instanceof fake.BaseClass); - assertTrue(instance2 instanceof fake.BaseClass); - assertTrue(instance3 instanceof fake.ChildClass); - }; - - function testGetStrictStaticMock() { - var staticMock = mockClassFactory.getStrictStaticMock(fake, - fake.ChildClass); - var mock = mockClassFactory.getStrictMockClass(fake, fake.ChildClass, 1); - - mock.foo(); - mock.bar(); - staticMock.staticFoo(); - mock.$replay(); - staticMock.$replay(); - - var instance = new fake.ChildClass(1); - instance.foo(); - instance.bar(); - fake.ChildClass.staticFoo(); - mock.$verify(); - staticMock.$verify(); - - assertTrue(instance instanceof fake.BaseClass); - assertTrue(instance instanceof fake.ChildClass); - assertThrows(function() { - mockClassFactory.getLooseStaticMock(fake, fake.ChildClass) - }); - }; - - function testGetStrictStaticMockKeepsStaticProperties() { - var OriginalChildClass = fake.ChildClass; - var staticMock = mockClassFactory.getStrictStaticMock(fake, - fake.ChildClass); - assertEquals(OriginalChildClass.staticProperty, - fake.ChildClass.staticProperty); - }; - - function testGetLooseStaticMockKeepsStaticProperties() { - var OriginalChildClass = fake.ChildClass; - var staticMock = mockClassFactory.getLooseStaticMock(fake, - fake.ChildClass); - assertEquals(OriginalChildClass.staticProperty, - fake.ChildClass.staticProperty); - }; - - function testGetLooseStaticMock() { - var staticMock = mockClassFactory.getLooseStaticMock(fake, - fake.ChildClass); - var mock = mockClassFactory.getStrictMockClass(fake, fake.ChildClass, 1); - - mock.foo(); - mock.bar(); - staticMock.staticFoo().$atLeastOnce(); - mock.$replay(); - staticMock.$replay(); - - var instance = new fake.ChildClass(1); - instance.foo(); - instance.bar(); - fake.ChildClass.staticFoo(); - fake.ChildClass.staticFoo(); - mock.$verify(); - staticMock.$verify(); - - assertTrue(instance instanceof fake.BaseClass); - assertTrue(instance instanceof fake.ChildClass); - assertThrows(function() { - mockClassFactory.getStrictStaticMock(fake, fake.ChildClass) - }); - }; - - function testFlexibleClassMockInstantiation() { - // This mock should be returned for all instances created with a number - // as the first argument. - var mock = mockClassFactory.getStrictMockClass(fake, fake.ChildClass, - matchers.isNumber); - mock.foo(); // Will be called by the first mock instance. - mock.foo(); // Will be called by the second mock instance. - mock.$replay(); - - var instance1 = new fake.ChildClass(1); - var instance2 = new fake.ChildClass(2); - instance1.foo(); - instance2.foo(); - assertThrows(function() { - new fake.ChildClass('foo'); - }); - mock.$verify(); - }; - - function testMockTopLevelClass() { - var mock = mockClassFactory.getStrictMockClass(goog.global, - goog.global.TopLevelBaseClass); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclock.js.svn-base deleted file mode 100644 index 30b62bc..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclock.js.svn-base +++ /dev/null @@ -1,410 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Mock Clock implementation for working with setTimeout, - * setInterval, clearTimeout and clearInterval within unit tests. - * - * Derived from jsUnitMockTimeout.js, contributed to JsUnit by - * Pivotal Computer Systems, www.pivotalsf.com - * - */ - -goog.provide('goog.testing.MockClock'); - -goog.require('goog.Disposable'); -goog.require('goog.testing.PropertyReplacer'); - - - -/** - * Class for unit testing code that uses setTimeout and clearTimeout. - * - * NOTE: If you are using MockClock to test code that makes use of - * goog.fx.Animation, then you must either: - * - * 1. Install and dispose of the MockClock in setUpPage() and tearDownPage() - * respectively (rather than setUp()/tearDown()). - * - * or - * - * 2. Ensure that every test clears the animation queue by calling - * mockClock.tick(x) at the end of each test function (where `x` is large - * enough to complete all animations). - * - * Otherwise, if any animation is left pending at the time that - * MockClock.dispose() is called, that will permanently prevent any future - * animations from playing on the page. - * - * @param {boolean=} opt_autoInstall Install the MockClock at construction time. - * @constructor - * @extends {goog.Disposable} - */ -goog.testing.MockClock = function(opt_autoInstall) { - goog.Disposable.call(this); - - /** - * Reverse-order queue of timers to fire. - * - * The last item of the queue is popped off. Insertion happens from the - * right. For example, the expiration times for each element of the queue - * might be in the order 300, 200, 200. - * - * @type {Array.<Object>} - * @private - */ - this.queue_ = []; - - /** - * Set of timeouts that should be treated as cancelled. - * - * Rather than removing cancelled timers directly from the queue, this set - * simply marks them as deleted so that they can be ignored when their - * turn comes up. The keys are the timeout keys that are cancelled, each - * mapping to true. - * - * @type {Object} - * @private - */ - this.deletedKeys_ = {}; - - if (opt_autoInstall) { - this.install(); - } -}; -goog.inherits(goog.testing.MockClock, goog.Disposable); - - -/** - * Count of the number of timeouts made. - * @type {number} - * @private - */ -goog.testing.MockClock.prototype.timeoutsMade_ = 0; - - -/** - * PropertyReplacer instance which overwrites and resets setTimeout, - * setInterval, etc. or null if the MockClock is not installed. - * @type {goog.testing.PropertyReplacer} - * @private - */ -goog.testing.MockClock.prototype.replacer_ = null; - - -/** - * Map of deleted keys. These keys represents keys that were deleted in a - * clearInterval, timeoutid -> object. - * @type {Object} - * @private - */ -goog.testing.MockClock.prototype.deletedKeys_ = null; - - -/** - * The current simulated time in milliseconds. - * @type {number} - * @private - */ -goog.testing.MockClock.prototype.nowMillis_ = 0; - - -/** - * Additional delay between the time a timeout was set to fire, and the time - * it actually fires. Useful for testing workarounds for this Firefox 2 bug: - * https://bugzilla.mozilla.org/show_bug.cgi?id=291386 - * May be negative. - * @type {number} - * @private - */ -goog.testing.MockClock.prototype.timeoutDelay_ = 0; - - -/** - * Installs the MockClock by overriding the window object's implementation of - * setTimeout, setInterval, clearTimeout and clearInterval. - */ -goog.testing.MockClock.prototype.install = function() { - if (!this.replacer_) { - var r = this.replacer_ = new goog.testing.PropertyReplacer(); - r.set(window, 'setTimeout', goog.bind(this.setTimeout_, this)); - r.set(window, 'setInterval', goog.bind(this.setInterval_, this)); - r.set(window, 'clearTimeout', goog.bind(this.clearTimeout_, this)); - r.set(window, 'clearInterval', goog.bind(this.clearInterval_, this)); - - // PropertyReplacer#set can't be called with renameable functions. - this.oldGoogNow_ = goog.now; - goog.now = goog.bind(this.getCurrentTime, this); - } -}; - - -/** - * Removes the MockClock's hooks into the window functions and revert to their - * original values. - */ -goog.testing.MockClock.prototype.uninstall = function() { - if (this.replacer_) { - this.replacer_.reset(); - this.replacer_ = null; - goog.now = this.oldGoogNow_; - } -}; - - -/** @override */ -goog.testing.MockClock.prototype.disposeInternal = function() { - this.uninstall(); - this.queue_ = null; - this.deletedKeys_ = null; - goog.testing.MockClock.superClass_.disposeInternal.call(this); -}; - - -/** - * Resets the MockClock, removing all timeouts that are scheduled and resets - * the fake timer count. - */ -goog.testing.MockClock.prototype.reset = function() { - this.queue_ = []; - this.deletedKeys_ = {}; - this.nowMillis_ = 0; - this.timeoutsMade_ = 0; - this.timeoutDelay_ = 0; -}; - - -/** - * Sets the amount of time between when a timeout is scheduled to fire and when - * it actually fires. - * @param {number} delay The delay in milliseconds. May be negative. - */ -goog.testing.MockClock.prototype.setTimeoutDelay = function(delay) { - this.timeoutDelay_ = delay; -}; - - -/** - * @return {number} delay The amount of time between when a timeout is - * scheduled to fire and when it actually fires, in milliseconds. May - * be negative. - */ -goog.testing.MockClock.prototype.getTimeoutDelay = function() { - return this.timeoutDelay_; -}; - - -/** - * Increments the MockClock's time by a given number of milliseconds, running - * any functions that are now overdue. - * @param {number=} opt_millis Number of milliseconds to increment the counter. - * If not specified, clock ticks 1 millisecond. - * @return {number} Current mock time in milliseconds. - */ -goog.testing.MockClock.prototype.tick = function(opt_millis) { - if (typeof opt_millis != 'number') { - opt_millis = 1; - } - var endTime = this.nowMillis_ + opt_millis; - this.runFunctionsWithinRange_(endTime); - this.nowMillis_ = endTime; - return endTime; -}; - - -/** - * @return {number} The number of timeouts that have been scheduled. - */ -goog.testing.MockClock.prototype.getTimeoutsMade = function() { - return this.timeoutsMade_; -}; - - -/** - * @return {number} The MockClock's current time in milliseconds. - */ -goog.testing.MockClock.prototype.getCurrentTime = function() { - return this.nowMillis_; -}; - - -/** - * @param {number} timeoutKey The timeout key. - * @return {boolean} Whether the timer has been set and not cleared, - * independent of the timeout's expiration. In other words, the timeout - * could have passed or could be scheduled for the future. Either way, - * this function returns true or false depending only on whether the - * provided timeoutKey represents a timeout that has been set and not - * cleared. - */ -goog.testing.MockClock.prototype.isTimeoutSet = function(timeoutKey) { - return timeoutKey <= this.timeoutsMade_ && !this.deletedKeys_[timeoutKey]; -}; - - -/** - * Runs any function that is scheduled before a certain time. Timeouts can - * be made to fire early or late if timeoutDelay_ is non-0. - * @param {number} endTime The latest time in the range, in milliseconds. - * @private - */ -goog.testing.MockClock.prototype.runFunctionsWithinRange_ = function( - endTime) { - var adjustedEndTime = endTime - this.timeoutDelay_; - - // Repeatedly pop off the last item since the queue is always sorted. - while (this.queue_.length && - this.queue_[this.queue_.length - 1].runAtMillis <= adjustedEndTime) { - var timeout = this.queue_.pop(); - - if (!(timeout.timeoutKey in this.deletedKeys_)) { - // Only move time forwards. - this.nowMillis_ = Math.max(this.nowMillis_, - timeout.runAtMillis + this.timeoutDelay_); - // Call timeout in global scope and pass the timeout key as the argument. - timeout.funcToCall.call(goog.global, timeout.timeoutKey); - // In case the interval was cleared in the funcToCall - if (timeout.recurring) { - this.scheduleFunction_( - timeout.timeoutKey, timeout.funcToCall, timeout.millis, true); - } - } - } -}; - - -/** - * Schedules a function to be run at a certain time. - * @param {number} timeoutKey The timeout key. - * @param {Function} funcToCall The function to call. - * @param {number} millis The number of milliseconds to call it in. - * @param {boolean} recurring Whether to function call should recur. - * @private - */ -goog.testing.MockClock.prototype.scheduleFunction_ = function( - timeoutKey, funcToCall, millis, recurring) { - var timeout = { - runAtMillis: this.nowMillis_ + millis, - funcToCall: funcToCall, - recurring: recurring, - timeoutKey: timeoutKey, - millis: millis - }; - - goog.testing.MockClock.insert_(timeout, this.queue_); -}; - - -/** - * Inserts a timer descriptor into a descending-order queue. - * - * Later-inserted duplicates appear at lower indices. For example, the - * asterisk in (5,4,*,3,2,1) would be the insertion point for 3. - * - * @param {Object} timeout The timeout to insert, with numerical runAtMillis - * property. - * @param {Array.<Object>} queue The queue to insert into, with each element - * having a numerical runAtMillis property. - * @private - */ -goog.testing.MockClock.insert_ = function(timeout, queue) { - // Although insertion of N items is quadratic, requiring goog.structs.Heap - // from a unit test will make tests more prone to breakage. Since unit - // tests are normally small, scalability is not a primary issue. - - // Find an insertion point. Since the queue is in reverse order (so we - // can pop rather than unshift), and later timers with the same time stamp - // should be executed later, we look for the element strictly greater than - // the one we are inserting. - - for (var i = queue.length; i != 0; i--) { - if (queue[i - 1].runAtMillis > timeout.runAtMillis) { - break; - } - queue[i] = queue[i - 1]; - } - - queue[i] = timeout; -}; - - -/** - * Maximum 32-bit signed integer. - * - * Timeouts over this time return immediately in many browsers, due to integer - * overflow. Such known browsers include Firefox, Chrome, and Safari, but not - * IE. - * - * @type {number} - * @private - */ -goog.testing.MockClock.MAX_INT_ = 2147483647; - - -/** - * Schedules a function to be called after {@code millis} milliseconds. - * Mock implementation for window.setTimeout - * @param {Function} funcToCall The function to call. - * @param {number} millis The number of milliseconds to call it after. - * @return {number} The number of timeouts created. - * @private - */ -goog.testing.MockClock.prototype.setTimeout_ = function(funcToCall, millis) { - if (millis > goog.testing.MockClock.MAX_INT_) { - throw Error( - 'Bad timeout value: ' + millis + '. Timeouts over MAX_INT ' + - '(24.8 days) cause timeouts to be fired ' + - 'immediately in most browsers, except for IE.'); - } - this.timeoutsMade_ = this.timeoutsMade_ + 1; - this.scheduleFunction_(this.timeoutsMade_, funcToCall, millis, false); - return this.timeoutsMade_; -}; - - -/** - * Schedules a function to be called every {@code millis} milliseconds. - * Mock implementation for window.setInterval - * @param {Function} funcToCall The function to call. - * @param {number} millis The number of milliseconds between calls. - * @return {number} The number of timeouts created. - * @private - */ -goog.testing.MockClock.prototype.setInterval_ = function(funcToCall, millis) { - this.timeoutsMade_ = this.timeoutsMade_ + 1; - this.scheduleFunction_(this.timeoutsMade_, funcToCall, millis, true); - return this.timeoutsMade_; -}; - - -/** - * Clears a timeout. - * Mock implementation for window.clearTimeout - * @param {number} timeoutKey The timeout key to clear. - * @private - */ -goog.testing.MockClock.prototype.clearTimeout_ = function(timeoutKey) { - this.deletedKeys_[timeoutKey] = true; -}; - - -/** - * Clears an interval. - * Mock implementation for window.clearInterval - * @param {number} timeoutKey The interval key to clear. - * @private - */ -goog.testing.MockClock.prototype.clearInterval_ = function(timeoutKey) { - this.deletedKeys_[timeoutKey] = true; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclock_test.html.svn-base deleted file mode 100644 index f168f83..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockclock_test.html.svn-base +++ /dev/null @@ -1,413 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.MockClock</title> -<script src="../base.js"></script> -<script> - goog.require('goog.functions'); - goog.require('goog.testing.MockClock'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - - function testMockClockWasInstalled() { - var clock = new goog.testing.MockClock(); - var originalTimeout = window.setTimeout; - clock.install(); - assertNotEquals(window.setTimeout, originalTimeout); - setTimeout(function() {}, 100); - assertEquals(1, clock.getTimeoutsMade()); - setInterval(function() {}, 200); - assertEquals(2, clock.getTimeoutsMade()); - clock.uninstall(); - assertEquals(window.setTimeout, originalTimeout); - assertNull(clock.replacer_); - } - - - function testSetTimeoutAndTick() { - var clock = new goog.testing.MockClock(true); - var m5 = false, m10 = false, m15 = false, m20 = false; - setTimeout(function() { m5 = true; }, 5); - setTimeout(function() { m10 = true; }, 10); - setTimeout(function() { m15 = true; }, 15); - setTimeout(function() { m20 = true; }, 20); - assertEquals(4, clock.getTimeoutsMade()); - - assertEquals(4, clock.tick(4)); - assertEquals(4, clock.getCurrentTime()); - - assertFalse(m5); - assertFalse(m10); - assertFalse(m15); - assertFalse(m20); - - assertEquals(5, clock.tick(1)); - assertEquals(5, clock.getCurrentTime()); - - assertTrue('m5 should now be true', m5); - assertFalse(m10); - assertFalse(m15); - assertFalse(m20); - - assertEquals(10, clock.tick(5)); - assertEquals(10, clock.getCurrentTime()); - - assertTrue('m5 should be true', m5); - assertTrue('m10 should now be true', m10); - assertFalse(m15); - assertFalse(m20); - - assertEquals(15, clock.tick(5)); - assertEquals(15, clock.getCurrentTime()); - - assertTrue('m5 should be true', m5); - assertTrue('m10 should be true', m10); - assertTrue('m15 should now be true', m15); - assertFalse(m20); - - assertEquals(20, clock.tick(5)); - assertEquals(20, clock.getCurrentTime()); - - assertTrue('m5 should be true', m5); - assertTrue('m10 should be true', m10); - assertTrue('m15 should be true', m15); - assertTrue('m20 should now be true', m20); - - clock.uninstall(); - } - - - function testSetInterval() { - var clock = new goog.testing.MockClock(true); - var times = 0 - setInterval(function() { times++; }, 100); - - clock.tick(500); - assertEquals(5, times); - clock.tick(100); - assertEquals(6, times); - clock.tick(100); - assertEquals(7, times); - clock.tick(50); - assertEquals(7, times); - clock.tick(50); - assertEquals(8, times); - - clock.uninstall(); - } - - - function testClearTimeout() { - var clock = new goog.testing.MockClock(true); - var ran = false; - var c = setTimeout(function() { ran = true; }, 100); - clock.tick(50); - assertFalse(ran); - clearTimeout(c); - clock.tick(100); - assertFalse(ran); - clock.uninstall(); - } - - - function testClearInterval() { - var clock = new goog.testing.MockClock(true); - var times = 0 - var c = setInterval(function() { times++; }, 100); - - clock.tick(500); - assertEquals(5, times); - clock.tick(100); - assertEquals(6, times); - clock.tick(100); - clearInterval(c); - assertEquals(7, times); - clock.tick(50); - assertEquals(7, times); - clock.tick(50); - assertEquals(7, times); - - clock.uninstall(); - } - - - function testClearInterval2() { - // Tests that we can clear the interval from inside the function - var clock = new goog.testing.MockClock(true); - var times = 0 - var c = setInterval(function() { - times++; - if (times == 6) { - clearInterval(c); - } - }, 100); - - clock.tick(500); - assertEquals(5, times); - clock.tick(100); - assertEquals(6, times); - clock.tick(100); - assertEquals(6, times); - clock.tick(50); - assertEquals(6, times); - clock.tick(50); - assertEquals(6, times); - - clock.uninstall(); - } - - - function testMockGoogNow() { - assertNotEquals(0, goog.now()); - var clock = new goog.testing.MockClock(true); - assertEquals(0, goog.now()); - clock.tick(50); - assertEquals(50, goog.now()); - clock.uninstall(); - assertNotEquals(50, goog.now()); - } - - - function testTimeoutDelay() { - var clock = new goog.testing.MockClock(true); - var m5 = false, m10 = false, m20 = false; - setTimeout(function() { m5 = true; }, 5); - setTimeout(function() { m10 = true; }, 10); - setTimeout(function() { m20 = true; }, 20); - - // Fire 3ms early, so m5 fires at t=2 - clock.setTimeoutDelay(-3); - clock.tick(1); - assertFalse(m5); - assertFalse(m10); - clock.tick(1); - assertTrue(m5); - assertFalse(m10); - - // Fire 3ms late, so m10 fires at t=13 - clock.setTimeoutDelay(3); - assertEquals(12, clock.tick(10)); - assertEquals(12, clock.getCurrentTime()); - assertFalse(m10); - clock.tick(1); - assertTrue(m10); - assertFalse(m20); - - // Fire 10ms early, so m20 fires now, since it's after t=10 - clock.setTimeoutDelay(-10); - assertFalse(m20); - assertEquals(14, clock.tick(1)); - assertEquals(14, clock.getCurrentTime()); - assertTrue(m20); - - clock.uninstall(); - } - - - function testTimerCallbackCanCreateIntermediateTimer() { - var clock = new goog.testing.MockClock(true); - var sequence = []; - - // Create 3 timers: 1, 2, and 3. Timer 1 should fire at T=1, timer 2 at - // T=2, and timer 3 at T=3. The catch: Timer 2 is created by the - // callback within timer 0. - - // Testing method: Create a simple string sequencing each timer and at - // what time it fired. - - setTimeout(function() { - sequence.push('timer1 at T=' + goog.now()); - setTimeout(function() { - sequence.push('timer2 at T=' + goog.now()); - }, 1); - }, 1); - - setTimeout(function() { - sequence.push('timer3 at T=' + goog.now()); - }, 3); - - clock.tick(4); - - assertEquals( - 'Each timer should fire in sequence at the correct time.', - 'timer1 at T=1, timer2 at T=2, timer3 at T=3', - sequence.join(', ')); - - clock.uninstall(); - } - - - function testCorrectArgumentsPassedToCallback() { - var clock = new goog.testing.MockClock(true); - var timeoutId; - var timeoutExecuted = false; - - timeoutId = setTimeout(function(arg) { - assertEquals('"this" must be goog.global', - goog.global, this); - assertEquals('The timeout ID must be the first parameter', - timeoutId, arg); - assertEquals('Exactly one argument must be passed', - 1, arguments.length); - timeoutExecuted = true; - }, 1); - - clock.tick(4); - - assertTrue('The timeout was not executed', timeoutExecuted); - - clock.uninstall(); - } - - - function testTickZero() { - var clock = new goog.testing.MockClock(true); - var calls = 0; - - setTimeout(function() { - assertEquals('I need to be first', 0, calls); - calls++; - }, 0); - - setTimeout(function() { - assertEquals('I need to be second', 1, calls); - calls++; - }, 0); - - clock.tick(0); - assertEquals(2, calls); - - setTimeout(function() { - assertEquals('I need to be third', 2, calls); - calls++; - }, 0); - - clock.tick(0); - assertEquals(3, calls); - - assertEquals('Time should still be zero', 0, goog.now()); - - clock.uninstall(); - } - - - function testReset() { - var clock = new goog.testing.MockClock(true); - - setTimeout(function() { - fail('Timeouts should be cleared after a reset'); - }, 0); - - clock.reset(); - clock.tick(999999); - clock.uninstall(); - } - - - function testQueueInsertionHelper() { - var queue = []; - - function queueToString() { - var buffer = []; - for (var i = 0; i < queue.length; i++) { - buffer.push(queue[i].runAtMillis); - } - return buffer.join(','); - } - - goog.testing.MockClock.insert_({runAtMillis: 2}, queue); - assertEquals('Only item', - '2', queueToString()); - - goog.testing.MockClock.insert_({runAtMillis: 4}, queue); - assertEquals('Biggest item', - '4,2', queueToString()); - - goog.testing.MockClock.insert_({runAtMillis: 5}, queue); - assertEquals('An even bigger item', - '5,4,2', queueToString()); - - goog.testing.MockClock.insert_({runAtMillis: 1}, queue); - assertEquals('Smallest item', - '5,4,2,1', queueToString()); - - goog.testing.MockClock.insert_({runAtMillis: 1, dup: true}, queue); - assertEquals('Duplicate smallest item', - '5,4,2,1,1', queueToString()); - assertTrue('Duplicate item comes at a smaller index', queue[3].dup); - - goog.testing.MockClock.insert_({runAtMillis: 3}, queue); - goog.testing.MockClock.insert_({runAtMillis: 3, dup:true}, queue); - assertEquals('Duplicate a middle item', - '5,4,3,3,2,1,1', queueToString()); - assertTrue('Duplicate item comes at a smaller index', queue[2].dup); - } - - function testIsTimeoutSet() { - var clock = new goog.testing.MockClock(true); - var timeoutKey = setTimeout(function(){}, 1); - assertTrue('Timeout ' + timeoutKey + ' should be set', - clock.isTimeoutSet(timeoutKey)); - var nextTimeoutKey = timeoutKey + 1; - assertFalse('Timeout ' + nextTimeoutKey + ' should not be set', - clock.isTimeoutSet(nextTimeoutKey)); - clearTimeout(timeoutKey); - assertFalse('Timeout ' + timeoutKey + ' should no longer be set', - clock.isTimeoutSet(timeoutKey)); - var newTimeoutKey = setTimeout(function(){}, 1); - clock.tick(5); - assertFalse('Timeout ' + timeoutKey + ' should not be set', - clock.isTimeoutSet(timeoutKey)); - assertTrue('Timeout ' + newTimeoutKey + ' should be set', - clock.isTimeoutSet(newTimeoutKey)); - clock.uninstall(); - } - - function testBalksOnTimeoutsGreaterThanMaxInt() { - // Browsers have trouble with timeout greater than max int, so we - // want Mock Clock to fail if this happens. - var clock = new goog.testing.MockClock(true); - // Functions on window don't seem to be able to throw exceptions in - // IE6. Explicitly reading the property makes it work. - var setTimeout = window.setTimeout; - assertThrows('Timeouts > MAX_INT should fail', - function() { - setTimeout(goog.nullFunction, 2147483648); - }); - assertThrows('Timeouts much greater than MAX_INT should fail', - function() { - setTimeout(goog.nullFunction, 2147483648 * 10); - }); - clock.uninstall(); - } - - function testCorrectSetTimeoutIsRestored() { - var original = window.setTimeout; - var safe = goog.functions.error('should not have been called'); - try { - window.setTimeout = safe; - var clock = new goog.testing.MockClock(true); - assertNotEquals('setTimeout is replaced', safe, window.setTimeout); - clock.uninstall(); - // NOTE: If this assertion proves to be flaky in IE, the string value of - // the two functions have to be compared as described in - // goog.testing.TestCase#finalize. - assertEquals('setTimeout is restored', safe, window.setTimeout); - } finally { - window.setTimeout = original; - } - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockcontrol.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockcontrol.js.svn-base deleted file mode 100644 index b77e19a..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockcontrol.js.svn-base +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview A MockControl holds a set of mocks for a particular test. - * It consolidates calls to $replay, $verify, and $tearDown, which simplifies - * the test and helps avoid omissions. - * - * You can create and control a mock: - * var mockFoo = mockControl.addMock(new MyMock(Foo)); - * - * MockControl also exposes some convenience functions that create - * controlled mocks for common mocks: StrictMock, LooseMock, - * FunctionMock, MethodMock, and GlobalFunctionMock. - * - */ - - -goog.provide('goog.testing.MockControl'); - -goog.require('goog.array'); -goog.require('goog.testing'); -goog.require('goog.testing.LooseMock'); -goog.require('goog.testing.MockInterface'); -goog.require('goog.testing.StrictMock'); - - - -/** - * Controls a set of mocks. Controlled mocks are replayed, verified, and - * cleaned-up at the same time. - * @constructor - */ -goog.testing.MockControl = function() { - /** - * The list of mocks being controlled. - * @type {Array.<goog.testing.MockInterface>} - * @private - */ - this.mocks_ = []; -}; - - -/** - * Takes control of this mock. - * @param {goog.testing.MockInterface} mock Mock to be controlled. - * @return {goog.testing.MockInterface} The same mock passed in, - * for convenience. - */ -goog.testing.MockControl.prototype.addMock = function(mock) { - this.mocks_.push(mock); - return mock; -}; - - -/** - * Calls replay on each controlled mock. - */ -goog.testing.MockControl.prototype.$replayAll = function() { - goog.array.forEach(this.mocks_, function(m) { - m.$replay(); - }); -}; - - -/** - * Calls reset on each controlled mock. - */ -goog.testing.MockControl.prototype.$resetAll = function() { - goog.array.forEach(this.mocks_, function(m) { - m.$reset(); - }); -}; - - -/** - * Calls verify on each controlled mock. - */ -goog.testing.MockControl.prototype.$verifyAll = function() { - goog.array.forEach(this.mocks_, function(m) { - m.$verify(); - }); -}; - - -/** - * Calls tearDown on each controlled mock, if necesssary. - */ -goog.testing.MockControl.prototype.$tearDown = function() { - goog.array.forEach(this.mocks_, function(m) { - // $tearDown if defined. - if (m.$tearDown) { - m.$tearDown(); - } - // TODO(user): Somehow determine if verifyAll should have been called - // but was not. - }); -}; - - -/** - * Creates a controlled StrictMock. Passes its arguments through to the - * StrictMock constructor. - * @param {Object} objectToMock The object to mock. - * @param {boolean=} opt_mockStaticMethods An optional argument denoting that - * a mock should be constructed from the static functions of a class. - * @param {boolean=} opt_createProxy An optional argument denoting that - * a proxy for the target mock should be created. - * @return {goog.testing.StrictMock} The mock object. - */ -goog.testing.MockControl.prototype.createStrictMock = function( - objectToMock, opt_mockStaticMethods, opt_createProxy) { - var m = new goog.testing.StrictMock(objectToMock, opt_mockStaticMethods, - opt_createProxy); - this.addMock(m); - return m; -}; - - -/** - * Creates a controlled LooseMock. Passes its arguments through to the - * LooseMock constructor. - * @param {Object} objectToMock The object to mock. - * @param {boolean=} opt_ignoreUnexpectedCalls Whether to ignore unexpected - * calls. - * @param {boolean=} opt_mockStaticMethods An optional argument denoting that - * a mock should be constructed from the static functions of a class. - * @param {boolean=} opt_createProxy An optional argument denoting that - * a proxy for the target mock should be created. - * @return {goog.testing.LooseMock} The mock object. - */ -goog.testing.MockControl.prototype.createLooseMock = function( - objectToMock, opt_ignoreUnexpectedCalls, - opt_mockStaticMethods, opt_createProxy) { - var m = new goog.testing.LooseMock(objectToMock, opt_ignoreUnexpectedCalls, - opt_mockStaticMethods, opt_createProxy); - this.addMock(m); - return m; -}; - - -/** - * Creates a controlled FunctionMock. Passes its arguments through to the - * FunctionMock constructor. - * @param {string=} opt_functionName The optional name of the function to mock - * set to '[anonymous mocked function]' if not passed in. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked function. - */ -goog.testing.MockControl.prototype.createFunctionMock = function( - opt_functionName, opt_strictness) { - var m = goog.testing.createFunctionMock(opt_functionName, opt_strictness); - this.addMock(m); - return m; -}; - - -/** - * Creates a controlled MethodMock. Passes its arguments through to the - * MethodMock constructor. - * @param {Object} scope The scope of the method to be mocked out. - * @param {string} functionName The name of the function we're going to mock. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked method. - */ -goog.testing.MockControl.prototype.createMethodMock = function( - scope, functionName, opt_strictness) { - var m = goog.testing.createMethodMock(scope, functionName, opt_strictness); - this.addMock(m); - return m; -}; - - -/** - * Creates a controlled MethodMock for a constructor. Passes its arguments - * through to the MethodMock constructor. See - * {@link goog.testing.createConstructorMock} for details. - * @param {Object} scope The scope of the constructor to be mocked out. - * @param {string} constructorName The name of the function we're going to mock. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked method. - */ -goog.testing.MockControl.prototype.createConstructorMock = function( - scope, constructorName, opt_strictness) { - var m = goog.testing.createConstructorMock(scope, constructorName, - opt_strictness); - this.addMock(m); - return m; -}; - - -/** - * Creates a controlled GlobalFunctionMock. Passes its arguments through to the - * GlobalFunctionMock constructor. - * @param {string} functionName The name of the function we're going to mock. - * @param {number=} opt_strictness One of goog.testing.Mock.LOOSE or - * goog.testing.mock.STRICT. The default is STRICT. - * @return {goog.testing.MockInterface} The mocked function. - */ -goog.testing.MockControl.prototype.createGlobalFunctionMock = function( - functionName, opt_strictness) { - var m = goog.testing.createGlobalFunctionMock(functionName, opt_strictness); - this.addMock(m); - return m; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockcontrol_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockcontrol_test.html.svn-base deleted file mode 100644 index 9eb5251..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockcontrol_test.html.svn-base +++ /dev/null @@ -1,127 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.MockControl</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.MockControl'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - - // Emulate the behavior of a mock. - function MockMock() { - this.replayCalled = false; - this.resetCalled = false; - this.verifyCalled = false; - this.tearDownCalled = false; - }; - - MockMock.prototype.$replay = function() { - this.replayCalled = true; - }; - - MockMock.prototype.$reset = function() { - this.resetCalled = true; - }; - - MockMock.prototype.$verify = function() { - this.verifyCalled = true; - }; - - function setUp() { - var mock = new goog.testing.Mock(MockMock); - }; - - function testAdd() { - var mockMock = new MockMock(); - - var control = new goog.testing.MockControl(); - assertEquals(mockMock, control.addMock(mockMock)); - } - - function testReplayAll() { - var mockMock1 = new MockMock(); - var mockMock2 = new MockMock(); - var mockMockExcluded = new MockMock(); - - var control = new goog.testing.MockControl(); - control.addMock(mockMock1); - control.addMock(mockMock2); - - control.$replayAll(); - assertTrue(mockMock1.replayCalled); - assertTrue(mockMock2.replayCalled); - assertFalse(mockMockExcluded.replayCalled); - } - - function testResetAll() { - var mockMock1 = new MockMock(); - var mockMock2 = new MockMock(); - var mockMockExcluded = new MockMock(); - - var control = new goog.testing.MockControl(); - control.addMock(mockMock1); - control.addMock(mockMock2); - - control.$resetAll(); - assertTrue(mockMock1.resetCalled); - assertTrue(mockMock2.resetCalled); - assertFalse(mockMockExcluded.resetCalled); - } - - function testVerifyAll() { - var mockMock1 = new MockMock(); - var mockMock2 = new MockMock(); - var mockMockExcluded = new MockMock(); - - var control = new goog.testing.MockControl(); - control.addMock(mockMock1); - control.addMock(mockMock2); - - control.$verifyAll(); - assertTrue(mockMock1.verifyCalled); - assertTrue(mockMock2.verifyCalled); - assertFalse(mockMockExcluded.verifyCalled); - } - - function testTearDownAll() { - var mockMock1 = new MockMock(); - var mockMock2 = new MockMock(); - var mockMockExcluded = new MockMock(); - - // $tearDown is optional. - mockMock2.$tearDown = function() { - this.tearDownCalled = true; - }; - mockMockExcluded.$tearDown = function() { - this.tearDownCalled = true; - }; - - var control = new goog.testing.MockControl(); - control.addMock(mockMock1); - control.addMock(mockMock2); - - control.$tearDown(); - - // mockMock2 has a tearDown method and is in the control. - assertTrue(mockMock2.tearDownCalled); - assertFalse(mockMock1.tearDownCalled); - assertFalse(mockMockExcluded.tearDownCalled); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockinterface.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockinterface.js.svn-base deleted file mode 100644 index 1a53470..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockinterface.js.svn-base +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview An interface that all mocks should share. - * @author nicksantos@google.com (Nick Santos) - */ - -goog.provide('goog.testing.MockInterface'); - - - -/** @interface */ -goog.testing.MockInterface = function() {}; - - -/** - * Write down all the expected functions that have been called on the - * mock so far. From here on out, future function calls will be - * compared against this list. - */ -goog.testing.MockInterface.prototype.$replay = function() {}; - - -/** - * Reset the mock. - */ -goog.testing.MockInterface.prototype.$reset = function() {}; - - -/** - * Assert that the expected function calls match the actual calls. - */ -goog.testing.MockInterface.prototype.$verify = function() {}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockmatchers.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockmatchers.js.svn-base deleted file mode 100644 index 7dc56f8..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockmatchers.js.svn-base +++ /dev/null @@ -1,395 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Matchers to be used with the mock utilities. They allow for - * flexible matching by type. Custom matchers can be created by passing a - * matcher function into an ArgumentMatcher instance. - * - * For examples, please see the unit test. - * - */ - - -goog.provide('goog.testing.mockmatchers'); -goog.provide('goog.testing.mockmatchers.ArgumentMatcher'); -goog.provide('goog.testing.mockmatchers.IgnoreArgument'); -goog.provide('goog.testing.mockmatchers.InstanceOf'); -goog.provide('goog.testing.mockmatchers.ObjectEquals'); -goog.provide('goog.testing.mockmatchers.RegexpMatch'); -goog.provide('goog.testing.mockmatchers.SaveArgument'); -goog.provide('goog.testing.mockmatchers.TypeOf'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.testing.asserts'); - - - -/** - * A simple interface for executing argument matching. A match in this case is - * testing to see if a supplied object fits a given criteria. True is returned - * if the given criteria is met. - * @param {Function=} opt_matchFn A function that evaluates a given argument - * and returns true if it meets a given criteria. - * @param {?string=} opt_matchName The name expressing intent as part of - * an error message for when a match fails. - * @constructor - */ -goog.testing.mockmatchers.ArgumentMatcher = - function(opt_matchFn, opt_matchName) { - /** - * A function that evaluates a given argument and returns true if it meets a - * given criteria. - * @type {Function} - * @private - */ - this.matchFn_ = opt_matchFn || null; - - /** - * A string indicating the match intent (e.g. isBoolean or isString). - * @type {?string} - * @private - */ - this.matchName_ = opt_matchName || null; -}; - - -/** - * A function that takes a match argument and an optional MockExpectation - * which (if provided) will get error information and returns whether or - * not it matches. - * @param {*} toVerify The argument that should be verified. - * @param {goog.testing.MockExpectation?=} opt_expectation The expectation - * for this match. - * @return {boolean} Whether or not a given argument passes verification. - */ -goog.testing.mockmatchers.ArgumentMatcher.prototype.matches = - function(toVerify, opt_expectation) { - if (this.matchFn_) { - var isamatch = this.matchFn_(toVerify); - if (!isamatch && opt_expectation) { - if (this.matchName_) { - opt_expectation.addErrorMessage('Expected: ' + - this.matchName_ + ' but was: ' + _displayStringForValue(toVerify)); - } else { - opt_expectation.addErrorMessage('Expected: missing mockmatcher' + - ' description but was: ' + - _displayStringForValue(toVerify)); - } - } - return isamatch; - } else { - throw Error('No match function defined for this mock matcher'); - } -}; - - - -/** - * A matcher that verifies that an argument is an instance of a given class. - * @param {Function} ctor The class that will be used for verification. - * @constructor - * @extends {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.InstanceOf = function(ctor) { - goog.testing.mockmatchers.ArgumentMatcher.call(this, - function(obj) { - return obj instanceof ctor; - // NOTE: Browser differences on ctor.toString() output - // make using that here problematic. So for now, just let - // people know the instanceOf() failed without providing - // browser specific details... - }, 'instanceOf()'); -}; -goog.inherits(goog.testing.mockmatchers.InstanceOf, - goog.testing.mockmatchers.ArgumentMatcher); - - - -/** - * A matcher that verifies that an argument is of a given type (e.g. "object"). - * @param {string} type The type that a given argument must have. - * @constructor - * @extends {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.TypeOf = function(type) { - goog.testing.mockmatchers.ArgumentMatcher.call(this, - function(obj) { - return goog.typeOf(obj) == type; - }, 'typeOf(' + type + ')'); -}; -goog.inherits(goog.testing.mockmatchers.TypeOf, - goog.testing.mockmatchers.ArgumentMatcher); - - - -/** - * A matcher that verifies that an argument matches a given RegExp. - * @param {RegExp} regexp The regular expression that the argument must match. - * @constructor - * @extends {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.RegexpMatch = function(regexp) { - goog.testing.mockmatchers.ArgumentMatcher.call(this, - function(str) { - return regexp.test(str); - }, 'match(' + regexp + ')'); -}; -goog.inherits(goog.testing.mockmatchers.RegexpMatch, - goog.testing.mockmatchers.ArgumentMatcher); - - - -/** - * A matcher that always returns true. It is useful when the user does not care - * for some arguments. - * For example: mockFunction('username', 'password', IgnoreArgument); - * @constructor - * @extends {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.IgnoreArgument = function() { - goog.testing.mockmatchers.ArgumentMatcher.call(this, - function() { - return true; - }, 'true'); -}; -goog.inherits(goog.testing.mockmatchers.IgnoreArgument, - goog.testing.mockmatchers.ArgumentMatcher); - - - -/** - * A matcher that verifies that the argument is an object that equals the given - * expected object, using a deep comparison. - * @param {Object} expectedObject An object to match against when - * verifying the argument. - * @constructor - * @extends {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.ObjectEquals = function(expectedObject) { - goog.testing.mockmatchers.ArgumentMatcher.call(this, - function(matchObject) { - assertObjectEquals('Expected equal objects', expectedObject, - matchObject); - return true; - }, 'objectEquals(' + expectedObject + ')'); -}; -goog.inherits(goog.testing.mockmatchers.ObjectEquals, - goog.testing.mockmatchers.ArgumentMatcher); - - -/** @override */ -goog.testing.mockmatchers.ObjectEquals.prototype.matches = - function(toVerify, opt_expectation) { - // Override the default matches implementation to capture the exception thrown - // by assertObjectEquals (if any) and add that message to the expectation. - try { - return goog.testing.mockmatchers.ObjectEquals.superClass_.matches.call( - this, toVerify, opt_expectation); - } catch (e) { - if (opt_expectation) { - opt_expectation.addErrorMessage(e.message); - } - return false; - } -}; - - - -/** - * A matcher that saves the argument that it is verifying so that your unit test - * can perform extra tests with this argument later. For example, if the - * argument is a callback method, the unit test can then later call this - * callback to test the asynchronous portion of the call. - * @param {goog.testing.mockmatchers.ArgumentMatcher|Function=} opt_matcher - * Argument matcher or matching function that will be used to validate the - * argument. By default, argument will always be valid. - * @param {?string=} opt_matchName The name expressing intent as part of - * an error message for when a match fails. - * @constructor - * @extends {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.SaveArgument = function(opt_matcher, opt_matchName) { - goog.testing.mockmatchers.ArgumentMatcher.call( - this, /** @type {Function} */ (opt_matcher), opt_matchName); - - if (opt_matcher instanceof goog.testing.mockmatchers.ArgumentMatcher) { - /** - * Delegate match requests to this matcher. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - * @private - */ - this.delegateMatcher_ = opt_matcher; - } else if (!opt_matcher) { - this.delegateMatcher_ = goog.testing.mockmatchers.ignoreArgument; - } -}; -goog.inherits(goog.testing.mockmatchers.SaveArgument, - goog.testing.mockmatchers.ArgumentMatcher); - - -/** @override */ -goog.testing.mockmatchers.SaveArgument.prototype.matches = function( - toVerify, opt_expectation) { - this.arg = toVerify; - if (this.delegateMatcher_) { - return this.delegateMatcher_.matches(toVerify, opt_expectation); - } - return goog.testing.mockmatchers.SaveArgument.superClass_.matches.call( - this, toVerify, opt_expectation); -}; - - -/** - * Saved argument that was verified. - * @type {*} - */ -goog.testing.mockmatchers.SaveArgument.prototype.arg; - - -/** - * An instance of the IgnoreArgument matcher. Returns true for all matches. - * @type {goog.testing.mockmatchers.IgnoreArgument} - */ -goog.testing.mockmatchers.ignoreArgument = - new goog.testing.mockmatchers.IgnoreArgument(); - - -/** - * A matcher that verifies that an argument is an array. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isArray = - new goog.testing.mockmatchers.ArgumentMatcher(goog.isArray, - 'isArray'); - - -/** - * A matcher that verifies that an argument is a array-like. A NodeList is an - * example of a collection that is very close to an array. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isArrayLike = - new goog.testing.mockmatchers.ArgumentMatcher(goog.isArrayLike, - 'isArrayLike'); - - -/** - * A matcher that verifies that an argument is a date-like. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isDateLike = - new goog.testing.mockmatchers.ArgumentMatcher(goog.isDateLike, - 'isDateLike'); - - -/** - * A matcher that verifies that an argument is a string. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isString = - new goog.testing.mockmatchers.ArgumentMatcher(goog.isString, - 'isString'); - - -/** - * A matcher that verifies that an argument is a boolean. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isBoolean = - new goog.testing.mockmatchers.ArgumentMatcher(goog.isBoolean, - 'isBoolean'); - - -/** - * A matcher that verifies that an argument is a number. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isNumber = - new goog.testing.mockmatchers.ArgumentMatcher(goog.isNumber, - 'isNumber'); - - -/** - * A matcher that verifies that an argument is a function. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isFunction = - new goog.testing.mockmatchers.ArgumentMatcher(goog.isFunction, - 'isFunction'); - - -/** - * A matcher that verifies that an argument is an object. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isObject = - new goog.testing.mockmatchers.ArgumentMatcher(goog.isObject, - 'isObject'); - - -/** - * A matcher that verifies that an argument is like a DOM node. - * @type {goog.testing.mockmatchers.ArgumentMatcher} - */ -goog.testing.mockmatchers.isNodeLike = - new goog.testing.mockmatchers.ArgumentMatcher(goog.dom.isNodeLike, - 'isNodeLike'); - - -/** - * A function that checks to see if an array matches a given set of - * expectations. The expectations array can be a mix of ArgumentMatcher - * implementations and values. True will be returned if values are identical or - * if a matcher returns a positive result. - * @param {Array} expectedArr An array of expectations which can be either - * values to check for equality or ArgumentMatchers. - * @param {Array} arr The array to match. - * @param {goog.testing.MockExpectation?=} opt_expectation The expectation - * for this match. - * @return {boolean} Whether or not the given array matches the expectations. - */ -goog.testing.mockmatchers.flexibleArrayMatcher = - function(expectedArr, arr, opt_expectation) { - return goog.array.equals(expectedArr, arr, function(a, b) { - var errCount = 0; - if (opt_expectation) { - errCount = opt_expectation.getErrorMessageCount(); - } - var isamatch = a === b || - a instanceof goog.testing.mockmatchers.ArgumentMatcher && - a.matches(b, opt_expectation); - var failureMessage = null; - if (!isamatch) { - failureMessage = goog.testing.asserts.findDifferences(a, b); - isamatch = !failureMessage; - } - if (!isamatch && opt_expectation) { - // If the error count changed, the match sent out an error - // message. If the error count has not changed, then - // we need to send out an error message... - if (errCount == opt_expectation.getErrorMessageCount()) { - // Use the _displayStringForValue() from assert.js - // for consistency... - if (!failureMessage) { - failureMessage = 'Expected: ' + _displayStringForValue(a) + - ' but was: ' + _displayStringForValue(b); - } - opt_expectation.addErrorMessage(failureMessage); - } - } - return isamatch; - }); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockmatchers_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockmatchers_test.html.svn-base deleted file mode 100644 index c8a9e17..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockmatchers_test.html.svn-base +++ /dev/null @@ -1,388 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - - @author earmbrust@google.com (Erick Armbrust) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.mockmatchers</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.testing.FunctionMock'); - goog.require('goog.testing.mockmatchers'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<div id="someDiv"> -</div> - -<script> - // A local reference to the mockmatchers namespace. - var matchers = goog.testing.mockmatchers; - - // Simple classes to test the InstanceOf matcher. - var foo = function() {}; - var bar = function() {}; - - // Simple class to test adding error messages to - // MockExpectation objects - function MockMock() { - this.errorMessages = []; - } - - var mockExpect = null; - - MockMock.prototype.addErrorMessage = function(msg) { - this.errorMessages.push(msg); - }; - - - MockMock.prototype.getErrorMessageCount = function() { - return this.errorMessages.length; - }; - - - function setUp() { - mockExpect = new MockMock(); - } - - - function testNoMatchName() { - // A matcher that does not fill in the match name - var matcher = new goog.testing.mockmatchers.ArgumentMatcher(goog.isString); - - // Make sure the lack of match name doesn't affect the ability - // to return True/False - assertTrue(matcher.matches('hello')); - assertFalse(matcher.matches(123)); - - // Make sure we handle the lack of a match name - assertFalse(matcher.matches(456, mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: missing mockmatcher description " + - "but was: <456> (Number)", mockExpect.errorMessages[0]); - } - - - function testInstanceOf() { - var matcher = new matchers.InstanceOf(foo); - assertTrue(matcher.matches(new foo())); - assertFalse(matcher.matches(new bar())); - - assertFalse(matcher.matches(new bar(), mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: instanceOf() " + - "but was: <[object Object]> (Object)", - mockExpect.errorMessages[0]); - } - - - function testTypeOf() { - var matcher = new matchers.TypeOf('number'); - assertTrue(matcher.matches(1)); - assertTrue(matcher.matches(2)); - assertFalse(matcher.matches('test')); - - assertFalse(matcher.matches(true, mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: typeOf(number) but was: <true> (Boolean)", - mockExpect.errorMessages[0]); - } - - - function testRegexpMatch() { - var matcher = new matchers.RegexpMatch(/^cho[dtp]/); - assertTrue(matcher.matches('chodhop')); - assertTrue(matcher.matches('chopper')); - assertFalse(matcher.matches('chocolate')); - assertFalse(matcher.matches(null)); - - assertFalse(matcher.matches('an anger', mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals('Expected: match(/^cho[dtp]/) but was: <an anger> (String)', - mockExpect.errorMessages[0]); - } - - - function testObjectEquals() { - // Test a simple match. - var simpleMatcher = new matchers.ObjectEquals({name: 'Bob', age: 42}); - assertTrue(simpleMatcher.matches({name: 'Bob', age: 42}, mockExpect)); - assertEquals(0, mockExpect.getErrorMessageCount()); - expectObjectEqualsFailure(simpleMatcher, {name: 'Bill', age: 42}, - 'name expected <Bob> (String) but was <Bill> (String)'); - expectObjectEqualsFailure(simpleMatcher, {name: 'Bob', age: 21}, - 'age expected <42> (Number) but was <21> (Number)'); - expectObjectEqualsFailure(simpleMatcher, {name: 'Bob'}, - 'property age not present in actual Object'); - expectObjectEqualsFailure(simpleMatcher, - {name: 'Bob', age: 42, country: 'USA'}, - 'property country not present in expected Object'); - - // Multiple mismatches should include multiple messages. - expectObjectEqualsFailure(simpleMatcher, {name: 'Jim', age: 36}, - 'name expected <Bob> (String) but was <Jim> (String)\n' + - ' age expected <42> (Number) but was <36> (Number)'); - } - - function testComplexObjectEquals() { - var complexMatcher = new matchers.ObjectEquals( - {a: 'foo', b: 2, c: ['bar', 3], d: {sub1: 'baz', sub2: -1}}); - assertTrue(complexMatcher.matches( - {a: 'foo', b: 2, c: ['bar', 3], d: {sub1: 'baz', sub2: -1}})); - expectObjectEqualsFailure(complexMatcher, - {a: 'foo', b: 2, c: ['bar', 3], d: {sub1: 'zap', sub2: -1}}, - 'sub1 expected <baz> (String) but was <zap> (String)'); - expectObjectEqualsFailure(complexMatcher, - {a: 'foo', b: 2, c: ['bar', 6], d: {sub1: 'baz', sub2: -1}}, - 'c[1] expected <3> (Number) but was <6> (Number)'); - } - - - function testSaveArgument() { - var saveMatcher = new matchers.SaveArgument(); - assertTrue(saveMatcher.matches(42)); - assertEquals(42, saveMatcher.arg); - - saveMatcher = new matchers.SaveArgument(goog.isString); - assertTrue(saveMatcher.matches('test')); - assertEquals('test', saveMatcher.arg); - assertFalse(saveMatcher.matches(17)); - assertEquals(17, saveMatcher.arg); - - saveMatcher = new matchers.SaveArgument(new matchers.ObjectEquals({ - value: 'value' - })); - assertTrue(saveMatcher.matches({ value: 'value' })); - assertEquals('value', saveMatcher.arg.value); - assertFalse(saveMatcher.matches('test')); - assertEquals('test', saveMatcher.arg); - } - - - function testIsArray() { - assertTrue(matchers.isArray.matches([])); - assertTrue(matchers.isArray.matches(new Array())); - assertFalse(matchers.isArray.matches('test')); - - assertFalse(matchers.isArray.matches({}, mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isArray but was: <[object Object]> (Object)", - mockExpect.errorMessages[0]); - } - - - function testIsArrayLike() { - var nodeList = (function() { - var div = document.createElement('div'); - div.appendChild(document.createElement('p')); - div.appendChild(document.createElement('p')); - return div.getElementsByTagName('div'); - })(); - - assertTrue(matchers.isArrayLike.matches([])); - assertTrue(matchers.isArrayLike.matches(new Array())); - assertTrue(matchers.isArrayLike.matches(nodeList)); - assertFalse(matchers.isArrayLike.matches('test')); - - assertFalse(matchers.isArrayLike.matches(3, mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isArrayLike but was: <3> (Number)", - mockExpect.errorMessages[0]); - } - - - function testIsDateLike() { - assertTrue(matchers.isDateLike.matches(new Date())); - assertFalse(matchers.isDateLike.matches('test')); - - assertFalse(matchers.isDateLike.matches('test', mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isDateLike but was: <test> (String)", - mockExpect.errorMessages[0]); - } - - - function testIsString() { - assertTrue(matchers.isString.matches('a')); - assertTrue(matchers.isString.matches('b')); - assertFalse(matchers.isString.matches(null)); - - assertFalse(matchers.isString.matches(null, mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isString but was: <null>", - mockExpect.errorMessages[0]); - } - - - function testIsBoolean() { - assertTrue(matchers.isBoolean.matches(true)); - assertTrue(matchers.isBoolean.matches(false)); - assertFalse(matchers.isBoolean.matches(null)); - - assertFalse(matchers.isBoolean.matches([], mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isBoolean but was: <> (Array)", - mockExpect.errorMessages[0]); - } - - - function testIsNumber() { - assertTrue(matchers.isNumber.matches(-1)); - assertTrue(matchers.isNumber.matches(1)); - assertTrue(matchers.isNumber.matches(1.25)); - assertFalse(matchers.isNumber.matches(null)); - - assertFalse(matchers.isNumber.matches('hello', mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isNumber but was: <hello> (String)", - mockExpect.errorMessages[0]); - } - - - function testIsFunction() { - assertTrue(matchers.isFunction.matches(function() {})); - assertFalse(matchers.isFunction.matches('test')); - - assertFalse(matchers.isFunction.matches({}, mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isFunction but was: <[object Object]> (Object)", - mockExpect.errorMessages[0]); - } - - - function testIsObject() { - assertTrue(matchers.isObject.matches({})); - assertTrue(matchers.isObject.matches(new Object())); - assertTrue(matchers.isObject.matches(new function() {})); - assertTrue(matchers.isObject.matches([])); - assertTrue(matchers.isObject.matches(new Array())); - assertTrue(matchers.isObject.matches(function() {})); - assertFalse(matchers.isObject.matches(null)); - - assertFalse(matchers.isObject.matches(1234, mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isObject but was: <1234> (Number)", - mockExpect.errorMessages[0]); - } - - - function testIsNodeLike() { - assertFalse(matchers.isNodeLike.matches({})); - assertFalse(matchers.isNodeLike.matches(1)); - assertFalse(matchers.isNodeLike.matches(function() {})); - assertFalse(matchers.isNodeLike.matches(false)); - assertTrue(matchers.isNodeLike.matches(document.body)); - assertTrue(matchers.isNodeLike.matches(goog.dom.getElement('someDiv'))); - - assertFalse(matchers.isNodeLike.matches('test', mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals("Expected: isNodeLike but was: <test> (String)", - mockExpect.errorMessages[0]); - } - - - function testIgnoreArgumentsMatcher() { - // ignoreArgument always returns true: - assertTrue(matchers.ignoreArgument.matches()); - assertTrue(matchers.ignoreArgument.matches(356)); - assertTrue(matchers.ignoreArgument.matches('str')); - assertTrue(matchers.ignoreArgument.matches(['array', 123, false])); - assertTrue(matchers.ignoreArgument.matches({'map': 1, key2: 'value2'})); - } - - - function testFlexibleArrayMatcher() { - // Test that basic lists are verified properly. - var a1 = [1, 'test']; - var a2 = [1, 'test']; - var a3 = [1, 'test', 'extra']; - assertTrue(matchers.flexibleArrayMatcher(a1, a2)); - assertFalse(matchers.flexibleArrayMatcher(a1, a3)); - - // Test that basic lists with basic class instances are verified properly. - var instance = new foo(); - a1 = [1, 'test', instance]; - a2 = [1, 'test', instance]; - a3 = [1, 'test', new foo()]; - assertTrue(matchers.flexibleArrayMatcher(a1, a2)); - assertTrue(matchers.flexibleArrayMatcher(a1, a3)); - - // Create an argument verifier that returns a consistent value. - var verifyValue = true; - var argVerifier = function() {}; - goog.inherits(argVerifier, matchers.ArgumentMatcher); - argVerifier.prototype.matches = function(arg) { - return verifyValue; - }; - - // Test that the arguments are always verified when the verifier returns - // true. - a1 = [1, 'test', new argVerifier()]; - a2 = [1, 'test', 'anything']; - a3 = [1, 'test', 12345]; - assertTrue(matchers.flexibleArrayMatcher(a1, a2)); - assertTrue(matchers.flexibleArrayMatcher(a1, a3)); - - // Now test the case when then verifier returns false. - verifyValue = false; - assertFalse(matchers.flexibleArrayMatcher(a1, a2)); - assertFalse(matchers.flexibleArrayMatcher(a1, a3)); - - // And test we report errors back up via the opt_expectation - assertFalse(matchers.flexibleArrayMatcher(a2, a3, mockExpect)); - assertEquals(1, mockExpect.errorMessages.length); - assertEquals( - 'Expected <anything> (String) but was <12345> (Number)\n' + - ' expected <anything> (String) but was <12345> (Number)', - mockExpect.errorMessages[0]); - - // And test we report errors found via the matcher - a1 = [1, goog.testing.mockmatchers.isString ]; - a2 = [1, 'test string']; - a3 = [1, null]; - assertTrue(matchers.flexibleArrayMatcher(a1, a2, mockExpect)); - assertFalse(matchers.flexibleArrayMatcher(a1, a3, mockExpect)); - // Old error is still there - assertEquals(2, mockExpect.errorMessages.length); - assertEquals( - 'Expected <anything> (String) but was <12345> (Number)\n' + - ' expected <anything> (String) but was <12345> (Number)', - mockExpect.errorMessages[0]); - // plus the new error... - assertEquals("Expected: isString but was: <null>", - mockExpect.errorMessages[1]); - } - - - /** - * Utility method for checking for an ObjectEquals match failure. Checks that - * the expected error message was included in the error messages appended to - * the expectation object. - * @param {goog.testing.mockmatchers.ArgumentMatcher.ObjectEquals} matcher - * The matcher to test against. - * @param {Object} matchObject The object to compare. - * @param {string=} opt_errorMsg The deep object comparison failure message - * to check for. - */ - function expectObjectEqualsFailure(matcher, matchObject, opt_errorMsg) { - mockExpect.errorMessages = []; - assertFalse(matcher.matches(matchObject, mockExpect)); - assertNotEquals(0, mockExpect.getErrorMessageCount()); - if (opt_errorMsg) { - assertContains(opt_errorMsg, mockExpect.errorMessages[0]); - } - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrandom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrandom.js.svn-base deleted file mode 100644 index a29df1b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrandom.js.svn-base +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview MockRandom provides a mechanism for specifying a stream of - * numbers to expect from calls to Math.random(). - * - */ - -goog.provide('goog.testing.MockRandom'); - -goog.require('goog.Disposable'); - - - -/** - * Class for unit testing code that uses Math.random. - * - * @param {Array.<number>} sequence The sequence of numbers to return. - * @param {boolean=} opt_install Whether to install the MockRandom at - * construction time. - * @extends {goog.Disposable} - * @constructor - */ -goog.testing.MockRandom = function(sequence, opt_install) { - goog.Disposable.call(this); - - /** - * The sequence of numbers to be returned by calls to random() - * @type {Array.<number>} - * @private - */ - this.sequence_ = sequence || []; - - /** - * The original Math.random function. - * @type {function(): number} - * @private - */ - this.mathRandom_ = Math.random; - - if (opt_install) { - this.install(); - } -}; -goog.inherits(goog.testing.MockRandom, goog.Disposable); - - -/** - * Whether this MockRandom has been installed. - * @type {boolean} - * @private - */ -goog.testing.MockRandom.prototype.installed_; - - -/** - * Installs this MockRandom as the system number generator. - */ -goog.testing.MockRandom.prototype.install = function() { - if (!this.installed_) { - Math.random = goog.bind(this.random, this); - this.installed_ = true; - } -}; - - -/** - * @return {number} The next number in the sequence. If there are no more values - * left, this will return a random number. - */ -goog.testing.MockRandom.prototype.random = function() { - return this.hasMoreValues() ? this.sequence_.shift() : this.mathRandom_(); -}; - - -/** - * @return {boolean} Whether there are more numbers left in the sequence. - */ -goog.testing.MockRandom.prototype.hasMoreValues = function() { - return this.sequence_.length > 0; -}; - - -/** - * Injects new numbers into the beginning of the sequence. - * @param {Array.<number>|number} values Number or array of numbers to inject. - */ -goog.testing.MockRandom.prototype.inject = function(values) { - if (goog.isArray(values)) { - this.sequence_ = values.concat(this.sequence_); - } else { - this.sequence_.splice(0, 0, values); - } -}; - - -/** - * Uninstalls the MockRandom. - */ -goog.testing.MockRandom.prototype.uninstall = function() { - if (this.installed_) { - Math.random = this.mathRandom_; - this.installed_ = false; - } -}; - - -/** @override */ -goog.testing.MockRandom.prototype.disposeInternal = function() { - this.uninstall(); - delete this.sequence_; - delete this.mathRandom_; - goog.testing.MockRandom.superClass_.disposeInternal.call(this); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrandom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrandom_test.html.svn-base deleted file mode 100644 index ebf3ff1..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrandom_test.html.svn-base +++ /dev/null @@ -1,56 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.MockRandom</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.MockRandom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - - function testMockRandomInstall() { - var random = new goog.testing.MockRandom([]); - var originalRandom = Math.random; - - assertFalse(!!random.installed_); - - random.install(); - assertTrue(random.installed_); - assertNotEquals(Math.random, originalRandom); - - random.uninstall(); - assertFalse(random.installed_); - assertEquals(originalRandom, Math.random); - } - - function testMockRandomRandom() { - var random = new goog.testing.MockRandom([], true); - - assertFalse(random.hasMoreValues()); - - random.inject(2); - assertTrue(random.hasMoreValues()); - assertEquals(2, Math.random()); - - random.inject([1, 2, 3]); - assertTrue(random.hasMoreValues()); - assertEquals(1, Math.random()); - assertEquals(2, Math.random()); - assertEquals(3, Math.random()); - assertFalse(random.hasMoreValues()); - assertNotUndefined(Math.random()); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrange.js.svn-base deleted file mode 100644 index a49389d..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrange.js.svn-base +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview LooseMock of goog.dom.AbstractRange. - * - */ - -goog.provide('goog.testing.MockRange'); - -goog.require('goog.dom.AbstractRange'); -goog.require('goog.testing.LooseMock'); - - - -/** - * LooseMock of goog.dom.AbstractRange. Useful because the mock framework cannot - * simply create a mock out of an abstract class, and cannot create a mock out - * of classes that implements __iterator__ because it relies on the default - * behavior of iterating through all of an object's properties. - * @constructor - * @extends {goog.testing.LooseMock} - */ -goog.testing.MockRange = function() { - goog.testing.LooseMock.call(this, goog.testing.MockRange.ConcreteRange_); -}; -goog.inherits(goog.testing.MockRange, goog.testing.LooseMock); - - -// *** Private helper class ************************************************* // - - - -/** - * Concrete subclass of goog.dom.AbstractRange that simply sets the abstract - * method __iterator__ to undefined so that javascript defaults to iterating - * through all of the object's properties. - * @constructor - * @extends {goog.dom.AbstractRange} - * @private - */ -goog.testing.MockRange.ConcreteRange_ = function() { - goog.dom.AbstractRange.call(this); -}; -goog.inherits(goog.testing.MockRange.ConcreteRange_, goog.dom.AbstractRange); - - -/** - * Undefine the iterator so the mock framework can loop through this class' - * properties. - * @type {undefined} - * @override - */ -goog.testing.MockRange.ConcreteRange_.prototype.__iterator__ = undefined; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrange_test.html.svn-base deleted file mode 100644 index d4b5324..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockrange_test.html.svn-base +++ /dev/null @@ -1,41 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.MockRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.MockRange'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - - /** - * Tests that a MockRange can be created successfully, a call to a mock - * method can be recorded, and the correct behavior replayed and verified. - */ - function testMockMethod() { - var mockRange = new goog.testing.MockRange(); - mockRange.getStartOffset().$returns(42); - mockRange.$replay(); - - assertEquals('Mock method should return recorded value', - 42, - mockRange.getStartOffset()); - mockRange.$verify(); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockstorage.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockstorage.js.svn-base deleted file mode 100644 index 2d191ab..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockstorage.js.svn-base +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2011 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Provides a JS storage class implementing the HTML5 Storage - * interface. - */ - - -goog.require('goog.structs.Map'); - - -goog.provide('goog.testing.MockStorage'); - - - -/** - * A JS storage instance, implementing the HMTL5 Storage interface. - * See http://www.w3.org/TR/webstorage/ for details. - * - * @constructor - * @implements {Storage} - */ -goog.testing.MockStorage = function() { - /** - * The underlying storage object. - * @type {goog.structs.Map} - * @private - */ - this.store_ = new goog.structs.Map(); - - /** - * The number of elements in the storage. - * @type {number} - */ - this.length = 0; -}; - - -/** - * Sets an item to the storage. - * @param {string} key Storage key. - * @param {*} value Storage value. Must be convertible to string. - */ -goog.testing.MockStorage.prototype.setItem = function(key, value) { - this.store_.set(key, String(value)); - this.length = this.store_.getCount(); -}; - - -/** - * Gets an item from the storage. The item returned is the "structured clone" - * of the value from setItem. In practice this means it's the value cast to a - * string. - * @param {string} key Storage key. - * @return {?string} Storage value for key; null if does not exist. - */ -goog.testing.MockStorage.prototype.getItem = function(key) { - var val = this.store_.get(key); - // Enforce that getItem returns string values. - return (val != null) ? /** @type {string} */ (val) : null; -}; - - -/** - * Removes and item from the storage. - * @param {string} key Storage key. - */ -goog.testing.MockStorage.prototype.removeItem = function(key) { - this.store_.remove(key); - this.length = this.store_.getCount(); -}; - - -/** - * Clears the storage. - */ -goog.testing.MockStorage.prototype.clear = function() { - this.store_.clear(); - this.length = 0; -}; - - -/** - * Returns the key at the given index. - * @param {number} index The index for the key. - * @return {?string} Key at the given index, null if not found. - */ -goog.testing.MockStorage.prototype.key = function(index) { - return this.store_.getKeys()[index] || null; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockstorage_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockstorage_test.html.svn-base deleted file mode 100644 index a36a88a..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockstorage_test.html.svn-base +++ /dev/null @@ -1,78 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2011 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.MockStorage</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.MockStorage'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - var instance; - - function setUp() { - instance = new goog.testing.MockStorage(); - } - - /** - * Tests the MockStorage interface. - */ - function testMockStorage() { - assertEquals(0, instance.length); - - instance.setItem('foo', 'bar'); - assertEquals(1, instance.length); - assertEquals('bar', instance.getItem('foo')); - assertEquals('foo', instance.key(0)); - - instance.setItem('foo', 'baz'); - assertEquals('baz', instance.getItem('foo')); - - instance.setItem('goo', 'gl'); - assertEquals(2, instance.length); - assertEquals('gl', instance.getItem('goo')); - assertEquals('goo', instance.key(1)); - - assertNull(instance.getItem('poogle')); - - instance.removeItem('foo'); - assertEquals(1, instance.length); - assertEquals('goo', instance.key(0)); - - instance.setItem('a', 12); - assertEquals('12', instance.getItem('a')); - instance.setItem('b', false); - assertEquals('false', instance.getItem('b')); - instance.setItem('c', {a: 1, b: 12}); - assertEquals('[object Object]', instance.getItem('c')); - - instance.clear(); - assertEquals(0, instance.length); - - // Test some special cases. - instance.setItem('emptyString', ''); - assertEquals('', instance.getItem('emptyString')); - instance.setItem('isNull', null); - assertEquals('null', instance.getItem('isNull')) - instance.setItem('isUndefined', undefined); - assertEquals('undefined', instance.getItem('isUndefined')) - instance.setItem('', 'empty key'); - assertEquals('empty key', instance.getItem('')); - assertEquals(4, instance.length); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockuseragent.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockuseragent.js.svn-base deleted file mode 100644 index ced41cd..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockuseragent.js.svn-base +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview MockUserAgent overrides goog.userAgent.getUserAgentString() - * depending on a specified configuration. - * - */ - -goog.provide('goog.testing.MockUserAgent'); - -goog.require('goog.Disposable'); -goog.require('goog.userAgent'); - - - -/** - * Class for unit testing code that uses goog.userAgent. - * - * @extends {goog.Disposable} - * @constructor - */ -goog.testing.MockUserAgent = function() { - goog.Disposable.call(this); - - /** - * The userAgent string used by goog.userAgent. - * @type {?string} - * @private - */ - this.userAgent_ = goog.userAgent.getUserAgentString(); - - /** - * The original goog.userAgent.getUserAgentString function. - * @type {function():?string} - * @private - */ - this.originalUserAgentFunction_ = goog.userAgent.getUserAgentString; - - /** - * The navigator object used by goog.userAgent - * @type {Object} - * @private - */ - this.navigator_ = goog.userAgent.getNavigator(); - - /** - * The original goog.userAgent.getNavigator function - * @type {function():Object} - * @private - */ - this.originalNavigatorFunction_ = goog.userAgent.getNavigator; -}; -goog.inherits(goog.testing.MockUserAgent, goog.Disposable); - - -/** - * Whether this MockUserAgent has been installed. - * @type {boolean} - * @private - */ -goog.testing.MockUserAgent.prototype.installed_; - - -/** - * Installs this MockUserAgent. - */ -goog.testing.MockUserAgent.prototype.install = function() { - if (!this.installed_) { - goog.userAgent.getUserAgentString = - goog.bind(this.getUserAgentString, this); - goog.userAgent.getNavigator = goog.bind(this.getNavigator, this); - this.installed_ = true; - } -}; - - -/** - * @return {?string} The userAgent set in this class. - */ -goog.testing.MockUserAgent.prototype.getUserAgentString = function() { - return this.userAgent_; -}; - - -/** - * @param {string} userAgent The desired userAgent string to use. - */ -goog.testing.MockUserAgent.prototype.setUserAgentString = function(userAgent) { - this.userAgent_ = userAgent; -}; - - -/** - * @return {Object} The Navigator set in this class. - */ -goog.testing.MockUserAgent.prototype.getNavigator = function() { - return this.navigator_; -}; - - -/** - * @param {Object} navigator The desired Navigator object to use. - */ -goog.testing.MockUserAgent.prototype.setNavigator = function(navigator) { - this.navigator_ = navigator; -}; - - -/** - * Uninstalls the MockUserAgent. - */ -goog.testing.MockUserAgent.prototype.uninstall = function() { - if (this.installed_) { - goog.userAgent.getUserAgentString = this.originalUserAgentFunction_; - goog.userAgent.getNavigator = this.originalNavigatorFunction_; - this.installed_ = false; - } -}; - - -/** @override */ -goog.testing.MockUserAgent.prototype.disposeInternal = function() { - this.uninstall(); - delete this.userAgent_; - delete this.originalUserAgentFunction_; - delete this.navigator_; - delete this.originalNavigatorFunction_; - goog.testing.MockUserAgent.superClass_.disposeInternal.call(this); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockuseragent_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockuseragent_test.html.svn-base deleted file mode 100644 index 2c9e525..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/mockuseragent_test.html.svn-base +++ /dev/null @@ -1,59 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - - @author andybons@google.com (Andrew Bonventre) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.MockUserAgent</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.MockUserAgent'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> -<script> - - function testMockUserAgentInstall() { - var userAgent = new goog.testing.MockUserAgent(); - - var originalUserAgentFunction = goog.userAgent.getUserAgentString; - - assertFalse(!!userAgent.installed_); - - userAgent.install(); - assertTrue(userAgent.installed_); - assertNotEquals(goog.userAgent.getUserAgentString, - originalUserAgentFunction); - - userAgent.uninstall(); - assertFalse(userAgent.installed_); - assertEquals(originalUserAgentFunction, goog.userAgent.getUserAgentString); - } - - function testMockUserAgentGetAgent() { - var uaString = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) ' + - 'AppleWebKit/525.13 (KHTML, like Gecko) ' + - 'Chrome/0.2.149.27 Safari/525.13'; - - var userAgent = new goog.testing.MockUserAgent(); - userAgent.setUserAgentString(uaString); - userAgent.install(); - - assertTrue(userAgent.installed_); - - assertEquals(uaString, goog.userAgent.getUserAgentString()); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/multitestrunner.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/multitestrunner.js.svn-base deleted file mode 100644 index 4c94b95..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/multitestrunner.js.svn-base +++ /dev/null @@ -1,1440 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utility for running multiple test files that utilize the same - * interface as goog.testing.TestRunner. Each test is run in series and their - * results aggregated. The main usecase for the MultiTestRunner is to allow - * the testing of all tests in a project locally. - * - */ - -goog.provide('goog.testing.MultiTestRunner'); -goog.provide('goog.testing.MultiTestRunner.TestFrame'); - -goog.require('goog.Timer'); -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.classes'); -goog.require('goog.events.EventHandler'); -goog.require('goog.functions'); -goog.require('goog.string'); -goog.require('goog.ui.Component'); -goog.require('goog.ui.ServerChart'); -goog.require('goog.ui.ServerChart.ChartType'); -goog.require('goog.ui.TableSorter'); - - - -/** - * A component for running multiple tests within the browser. - * @param {goog.dom.DomHelper=} opt_domHelper A DOM helper. - * @extends {goog.ui.Component} - * @constructor - */ -goog.testing.MultiTestRunner = function(opt_domHelper) { - goog.ui.Component.call(this, opt_domHelper); - - /** - * Array of tests to execute, when combined with the base path this should be - * a relative path to the test from the page containing the multi testrunner. - * @type {Array.<string>} - * @private - */ - this.allTests_ = []; - - /** - * Tests that match the filter function. - * @type {Array.<string>} - * @private - */ - this.activeTests_ = []; - - /** - * An event handler for handling events. - * @type {goog.events.EventHandler} - * @private - */ - this.eh_ = new goog.events.EventHandler(this); - - /** - * A table sorter for the stats. - * @type {goog.ui.TableSorter} - * @private - */ - this.tableSorter_ = new goog.ui.TableSorter(this.dom_); -}; -goog.inherits(goog.testing.MultiTestRunner, goog.ui.Component); - - -/** - * Default maximimum amount of time to spend at each stage of the test. - * @type {number} - */ -goog.testing.MultiTestRunner.DEFAULT_TIMEOUT_MS = 45 * 1000; - - -/** - * Messages corresponding to the numeric states. - * @type {Array.<string>} - */ -goog.testing.MultiTestRunner.STATES = [ - 'waiting for test runner', - 'initializing tests', - 'waiting for tests to finish' -]; - - -/** - * The test suite's name. - * @type {string} name - * @private - */ -goog.testing.MultiTestRunner.prototype.name_ = ''; - - -/** - * The base path used to resolve files within the allTests_ array. - * @type {string} - * @private - */ -goog.testing.MultiTestRunner.prototype.basePath_ = ''; - - -/** - * A set of tests that have finished. All extant keys map to true. - * @type {Object.<boolean>} - * @private - */ -goog.testing.MultiTestRunner.prototype.finished_ = null; - - -/** - * Whether the report should contain verbose information about the passes. - * @type {boolean} - * @private - */ -goog.testing.MultiTestRunner.prototype.verbosePasses_ = false; - - -/** - * Whether to hide passing tests completely in the report, makes verbosePasses_ - * obsolete. - * @type {boolean} - * @private - */ -goog.testing.MultiTestRunner.prototype.hidePasses_ = false; - - -/** - * Flag used to tell the test runner to stop after the current test. - * @type {boolean} - * @private - */ -goog.testing.MultiTestRunner.prototype.stopped_ = false; - - -/** - * Flag indicating whether the test runner is active. - * @type {boolean} - * @private - */ -goog.testing.MultiTestRunner.prototype.active_ = false; - - -/** - * Index of the next test to run. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.prototype.startedCount_ = 0; - - -/** - * Count of the results received so far. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.prototype.resultCount_ = 0; - - -/** - * Number of passes so far. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.prototype.passes_ = 0; - - -/** - * Timestamp for the current start time. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.prototype.startTime_ = 0; - - -/** - * Only tests whose paths patch this filter function will be - * executed. - * @type {function(string): boolean} - * @private - */ -goog.testing.MultiTestRunner.prototype.filterFn_ = goog.functions.TRUE; - - -/** - * Number of milliseconds to wait for loading and initialization steps. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.prototype.timeoutMs_ = - goog.testing.MultiTestRunner.DEFAULT_TIMEOUT_MS; - - -/** - * An array of objects containing stats about the tests. - * @type {Array.<Object>?} - * @private - */ -goog.testing.MultiTestRunner.prototype.stats_ = null; - - -/** - * Reference to the start button element. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.startButtonEl_ = null; - - -/** - * Reference to the stop button element. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.stopButtonEl_ = null; - - -/** - * Reference to the log element. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.logEl_ = null; - - -/** - * Reference to the report element. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.reportEl_ = null; - - -/** - * Reference to the stats element. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.statsEl_ = null; - - -/** - * Reference to the progress bar's element. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.progressEl_ = null; - - -/** - * Reference to the progress bar's inner row element. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.progressRow_ = null; - - -/** - * Reference to the log tab. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.logTabEl_ = null; - - -/** - * Reference to the report tab. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.reportTabEl_ = null; - - -/** - * Reference to the stats tab. - * @type {Element} - * @private - */ -goog.testing.MultiTestRunner.prototype.statsTabEl_ = null; - - -/** - * The number of tests to run at a time. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.prototype.poolSize_ = 1; - - -/** - * The size of the stats bucket for the number of files loaded histogram. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.prototype.numFilesStatsBucketSize_ = 20; - - -/** - * The size of the stats bucket in ms for the run time histogram. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.prototype.runTimeStatsBucketSize_ = 500; - - -/** - * Sets the name for the test suite. - * @param {string} name The suite's name. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.setName = function(name) { - this.name_ = name; - return this; -}; - - -/** - * Returns the name for the test suite. - * @return {string} The name for the test suite. - */ -goog.testing.MultiTestRunner.prototype.getName = function() { - return this.name_; -}; - - -/** - * Sets the basepath that tests added using addTests are resolved with. - * @param {string} path The relative basepath. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.setBasePath = function(path) { - this.basePath_ = path; - return this; -}; - - -/** - * Returns the basepath that tests added using addTests are resolved with. - * @return {string} The basepath that tests added using addTests are resolved - * with. - */ -goog.testing.MultiTestRunner.prototype.getBasePath = function() { - return this.basePath_; -}; - - -/** - * Sets whether the report should contain verbose information for tests that - * pass. - * @param {boolean} verbose Whether report should be verbose. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.setVerbosePasses = function(verbose) { - this.verbosePasses_ = verbose; - return this; -}; - - -/** - * Returns whether the report should contain verbose information for tests that - * pass. - * @return {boolean} Whether the report should contain verbose information for - * tests that pass. - */ -goog.testing.MultiTestRunner.prototype.getVerbosePasses = function() { - return this.verbosePasses_; -}; - - -/** - * Sets whether the report should contain passing tests at all, makes - * setVerbosePasses obsolete. - * @param {boolean} hide Whether report should not contain passing tests. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.setHidePasses = function(hide) { - this.hidePasses_ = hide; - return this; -}; - - -/** - * Returns whether the report should contain passing tests at all, makes - * setVerbosePasses obsolete. - * @return {boolean} Whether the report should contain passing tests at all, - * makes setVerbosePasses obsolete. - */ -goog.testing.MultiTestRunner.prototype.getHidePasses = function() { - return this.hidePasses_; -}; - - -/** - * Sets the bucket sizes for the histograms. - * @param {number} f Bucket size for num files loaded histogram. - * @param {number} t Bucket size for run time histogram. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.setStatsBucketSizes = function(f, t) { - this.numFilesStatsBucketSize_ = f; - this.runTimeStatsBucketSize_ = t; - return this; -}; - - -/** - * Sets the number of milliseconds to wait for the page to load, initialize and - * run the tests. - * @param {number} timeout Time in milliseconds. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.setTimeout = function(timeout) { - this.timeoutMs_ = timeout; - return this; -}; - - -/** - * Returns the number of milliseconds to wait for the page to load, initialize - * and run the tests. - * @return {number} The number of milliseconds to wait for the page to load, - * initialize and run the tests. - */ -goog.testing.MultiTestRunner.prototype.getTimeout = function() { - return this.timeoutMs_; -}; - - -/** - * Sets the number of tests that can be run at the same time. This only improves - * performance due to the amount of time spent loading the tests. - * @param {number} size The number of tests to run at a time. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.setPoolSize = function(size) { - this.poolSize_ = size; - return this; -}; - - -/** - * Returns the number of tests that can be run at the same time. This only - * improves performance due to the amount of time spent loading the tests. - * @return {number} The number of tests that can be run at the same time. This - * only improves performance due to the amount of time spent loading the - * tests. - */ -goog.testing.MultiTestRunner.prototype.getPoolSize = function() { - return this.poolSize_; -}; - - -/** - * Sets a filter function. Only test paths that match the filter function - * will be executed. - * @param {function(string): boolean} filterFn Filters test paths. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.setFilterFunction = function(filterFn) { - this.filterFn_ = filterFn; - return this; -}; - - -/** - * Returns a filter function. Only test paths that match the filter function - * will be executed. - * @return {function(string): boolean} A filter function. Only test paths that - * match the filter function will be executed. - - */ -goog.testing.MultiTestRunner.prototype.getFilterFunction = function() { - return this.filterFn_; -}; - - -/** - * Adds an array of tests to the tests that the test runner should execute. - * @param {Array.<string>} tests Adds tests to the test runner. - * @return {goog.testing.MultiTestRunner} Instance for chaining. - */ -goog.testing.MultiTestRunner.prototype.addTests = function(tests) { - goog.array.extend(this.allTests_, tests); - return this; -}; - - -/** - * Returns the list of all tests added to the runner. - * @return {Array.<string>} The list of all tests added to the runner. - */ -goog.testing.MultiTestRunner.prototype.getAllTests = function() { - return this.allTests_; -}; - - -/** - * Returns the list of tests that will be run when start() is called. - * @return {Array.<string>} The list of tests that will be run when start() is - * called. - */ -goog.testing.MultiTestRunner.prototype.getTestsToRun = function() { - return goog.array.filter(this.allTests_, this.filterFn_); -}; - - -/** - * Returns a list of tests from runner that have been marked as failed. - * @return {Array.<string>} A list of tests from runner that have been marked as - * failed. - */ -goog.testing.MultiTestRunner.prototype.getTestsThatFailed = function() { - var stats = this.stats_; - var failedTests = []; - if (stats) { - for (var i = 0, stat; stat = stats[i]; i++) { - if (!stat.success) { - failedTests.push(stat.testFile); - } - } - } - return failedTests; -}; - - -/** - * Deletes and re-creates the progress table inside the progess element. - * @private - */ -goog.testing.MultiTestRunner.prototype.resetProgressDom_ = function() { - goog.dom.removeChildren(this.progressEl_); - var progressTable = this.dom_.createDom('table'); - var progressTBody = this.dom_.createDom('tbody'); - this.progressRow_ = this.dom_.createDom('tr'); - for (var i = 0; i < this.activeTests_.length; i++) { - var progressCell = this.dom_.createDom('td'); - this.progressRow_.appendChild(progressCell); - } - progressTBody.appendChild(this.progressRow_); - progressTable.appendChild(progressTBody); - this.progressEl_.appendChild(progressTable); -}; - - -/** @override */ -goog.testing.MultiTestRunner.prototype.createDom = function() { - goog.testing.MultiTestRunner.superClass_.createDom.call(this); - var el = this.getElement(); - el.className = goog.getCssName('goog-testrunner'); - - this.progressEl_ = this.dom_.createDom('div'); - this.progressEl_.className = goog.getCssName('goog-testrunner-progress'); - el.appendChild(this.progressEl_); - - var buttons = this.dom_.createDom('div'); - buttons.className = goog.getCssName('goog-testrunner-buttons'); - this.startButtonEl_ = this.dom_.createDom('button', null, 'Start'); - this.stopButtonEl_ = - this.dom_.createDom('button', {'disabled': true}, 'Stop'); - buttons.appendChild(this.startButtonEl_); - buttons.appendChild(this.stopButtonEl_); - el.appendChild(buttons); - - this.eh_.listen(this.startButtonEl_, 'click', - this.onStartClicked_); - this.eh_.listen(this.stopButtonEl_, 'click', - this.onStopClicked_); - - this.logEl_ = this.dom_.createElement('div'); - this.logEl_.className = goog.getCssName('goog-testrunner-log'); - el.appendChild(this.logEl_); - - this.reportEl_ = this.dom_.createElement('div'); - this.reportEl_.className = goog.getCssName('goog-testrunner-report'); - this.reportEl_.style.display = 'none'; - el.appendChild(this.reportEl_); - - this.statsEl_ = this.dom_.createElement('div'); - this.statsEl_.className = goog.getCssName('goog-testrunner-stats'); - this.statsEl_.style.display = 'none'; - el.appendChild(this.statsEl_); - - this.logTabEl_ = this.dom_.createDom('div', null, 'Log'); - this.logTabEl_.className = goog.getCssName('goog-testrunner-logtab') + ' ' + - goog.getCssName('goog-testrunner-activetab'); - el.appendChild(this.logTabEl_); - - this.reportTabEl_ = this.dom_.createDom('div', null, 'Report'); - this.reportTabEl_.className = goog.getCssName('goog-testrunner-reporttab'); - el.appendChild(this.reportTabEl_); - - this.statsTabEl_ = this.dom_.createDom('div', null, 'Stats'); - this.statsTabEl_.className = goog.getCssName('goog-testrunner-statstab'); - el.appendChild(this.statsTabEl_); - - this.eh_.listen(this.logTabEl_, 'click', this.onLogTabClicked_); - this.eh_.listen(this.reportTabEl_, 'click', this.onReportTabClicked_); - this.eh_.listen(this.statsTabEl_, 'click', this.onStatsTabClicked_); - -}; - - -/** @override */ -goog.testing.MultiTestRunner.prototype.disposeInternal = function() { - goog.testing.MultiTestRunner.superClass_.disposeInternal.call(this); - this.tableSorter_.dispose(); - this.eh_.dispose(); - this.startButtonEl_ = null; - this.stopButtonEl_ = null; - this.logEl_ = null; - this.reportEl_ = null; - this.progressEl_ = null; - this.logTabEl_ = null; - this.reportTabEl_ = null; - this.statsTabEl_ = null; - this.statsEl_ = null; -}; - - -/** - * Starts executing the tests. - */ -goog.testing.MultiTestRunner.prototype.start = function() { - this.startButtonEl_.disabled = true; - this.stopButtonEl_.disabled = false; - this.stopped_ = false; - this.active_ = true; - this.finished_ = {}; - this.activeTests_ = this.getTestsToRun(); - this.startedCount_ = 0; - this.resultCount_ = 0; - this.passes_ = 0; - this.stats_ = []; - this.startTime_ = goog.now(); - - this.resetProgressDom_(); - goog.dom.removeChildren(this.logEl_); - - this.resetReport_(); - this.clearStats_(); - this.showTab_(0); - - // Ensure the pool isn't too big. - while (this.getChildCount() > this.poolSize_) { - this.removeChildAt(0, true).dispose(); - } - - // Start a test in each runner. - for (var i = 0; i < this.poolSize_; i++) { - if (i >= this.getChildCount()) { - var testFrame = new goog.testing.MultiTestRunner.TestFrame( - this.basePath_, this.timeoutMs_, this.verbosePasses_, this.dom_); - this.addChild(testFrame, true); - } - this.runNextTest_( - /** @type {goog.testing.MultiTestRunner.TestFrame} */ - (this.getChildAt(i))); - } -}; - - -/** - * Logs a message to the log window. - * @param {string} msg A message to log. - */ -goog.testing.MultiTestRunner.prototype.log = function(msg) { - if (msg != '.') { - msg = this.getTimeStamp_() + ' : ' + msg; - } - - this.logEl_.appendChild(this.dom_.createDom('div', null, msg)); - - // Autoscroll if we're near the bottom. - var top = this.logEl_.scrollTop; - var height = this.logEl_.scrollHeight - this.logEl_.offsetHeight; - if (top == 0 || top > height - 50) { - this.logEl_.scrollTop = height; - } -}; - - -/** - * Processes a result returned from a TestFrame. If there are tests remaining - * it will trigger the next one to be run, otherwise if there are no tests and - * all results have been recieved then it will call finish. - * @param {goog.testing.MultiTestRunner.TestFrame} frame The frame that just - * finished. - */ -goog.testing.MultiTestRunner.prototype.processResult = function(frame) { - var success = frame.isSuccess(); - var report = frame.getReport(); - var test = frame.getTestFile(); - - this.stats_.push(frame.getStats()); - this.finished_[test] = true; - - var prefix = success ? '' : '*** FAILURE *** '; - this.log(prefix + - this.trimFileName_(test) + ' : ' + (success ? 'Passed' : 'Failed')); - - this.resultCount_++; - - if (success) { - this.passes_++; - } - - this.drawProgressSegment_(test, success); - this.writeCurrentSummary_(); - if (!(success && this.hidePasses_)) { - this.drawTestResult_(test, success, report); - } - - if (!this.stopped_ && this.startedCount_ < this.activeTests_.length) { - this.runNextTest_(frame); - } else if (this.resultCount_ == this.activeTests_.length) { - this.finish_(); - } -}; - - -/** - * Runs the next available test, if there are any left. - * @param {goog.testing.MultiTestRunner.TestFrame} frame Where to run the test. - * @private - */ -goog.testing.MultiTestRunner.prototype.runNextTest_ = function(frame) { - if (this.startedCount_ < this.activeTests_.length) { - var nextTest = this.activeTests_[this.startedCount_++]; - this.log(this.trimFileName_(nextTest) + ' : Loading'); - frame.runTest(nextTest); - } -}; - - -/** - * Handles the test finishing, processing the results and rendering the report. - * @private - */ -goog.testing.MultiTestRunner.prototype.finish_ = function() { - if (this.stopped_) { - this.log('Stopped'); - } else { - this.log('Finished'); - } - - this.startButtonEl_.disabled = false; - this.stopButtonEl_.disabled = true; - this.active_ = false; - - this.showTab_(1); - this.drawStats_(); - - // Remove all the test frames - while (this.getChildCount() > 0) { - this.removeChildAt(0, true).dispose(); - } - - // Compute tests that did not finish before the stop button was hit. - var unfinished = []; - for (var i = 0; i < this.activeTests_.length; i++) { - var test = this.activeTests_[i]; - if (!this.finished_[test]) { - unfinished.push(test); - } - } - - if (unfinished.length) { - this.reportEl_.appendChild(goog.dom.createDom('pre', undefined, - 'Theses tests did not finish:\n' + unfinished.join('\n'))); - } -}; - - -/** - * Resets the report, clearing out all children and drawing the initial summary. - * @private - */ -goog.testing.MultiTestRunner.prototype.resetReport_ = function() { - goog.dom.removeChildren(this.reportEl_); - var summary = this.dom_.createDom('div'); - summary.className = goog.getCssName('goog-testrunner-progress-summary'); - this.reportEl_.appendChild(summary); - this.writeCurrentSummary_(); -}; - - -/** - * Draws the stats for the test run. - * @private - */ -goog.testing.MultiTestRunner.prototype.drawStats_ = function() { - this.drawFilesHistogram_(); - - // Only show time stats if pool size is 1, otherwise times are wrong. - if (this.poolSize_ == 1) { - this.drawRunTimePie_(); - this.drawTimeHistogram_(); - } - - this.drawWorstTestsTable_(); -}; - - -/** - * Draws the histogram showing number of files loaded. - * @private - */ -goog.testing.MultiTestRunner.prototype.drawFilesHistogram_ = function() { - this.drawStatsHistogram_( - 'numFilesLoaded', - this.numFilesStatsBucketSize_, - goog.functions.identity, - 500, - 'Histogram showing distribution of\nnumber of files loaded per test'); -}; - - -/** - * Draws the histogram showing how long each test took to complete. - * @private - */ -goog.testing.MultiTestRunner.prototype.drawTimeHistogram_ = function() { - this.drawStatsHistogram_( - 'totalTime', - this.runTimeStatsBucketSize_, - function(x) { return x / 1000; }, - 500, - 'Histogram showing distribution of\ntime spent running tests in s'); -}; - - -/** - * Draws a stats histogram. - * @param {string} statsField Field of the stats object to graph. - * @param {number} bucketSize The size for the histogram's buckets. - * @param {function(*, ...[*]): *} valueTransformFn Function for transforming - * the x-labels value for display. - * @param {number} width The width in pixels of the graph. - * @param {string} title The graph's title. - * @private - */ -goog.testing.MultiTestRunner.prototype.drawStatsHistogram_ = function( - statsField, bucketSize, valueTransformFn, width, title) { - - var hist = {}, data = [], xlabels = [], ylabels = []; - var max = 0; - for (var i = 0; i < this.stats_.length; i++) { - var num = this.stats_[i][statsField]; - var bucket = Math.floor(num / bucketSize) * bucketSize; - if (bucket > max) { - max = bucket; - } - if (!hist[bucket]) { - hist[bucket] = 1; - } else { - hist[bucket]++; - } - } - var maxBucketSize = 0; - for (var i = 0; i <= max; i += bucketSize) { - xlabels.push(valueTransformFn(i)); - var count = hist[i] || 0; - if (count > maxBucketSize) { - maxBucketSize = count; - } - data.push(count); - } - var diff = Math.max(1, Math.ceil(maxBucketSize / 10)); - for (var i = 0; i <= maxBucketSize; i += diff) { - ylabels.push(i); - } - var chart = new goog.ui.ServerChart( - goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR, width, 250); - chart.setTitle(title); - chart.addDataSet(data, 'ff9900'); - chart.setLeftLabels(ylabels); - chart.setGridY(ylabels.length - 1); - chart.setXLabels(xlabels); - chart.render(this.statsEl_); -}; - - -/** - * Draws a pie chart showing the percentage of time spent running the tests - * compared to loading them etc. - * @private - */ -goog.testing.MultiTestRunner.prototype.drawRunTimePie_ = function() { - var totalTime = 0, runTime = 0; - for (var i = 0; i < this.stats_.length; i++) { - var stat = this.stats_[i]; - totalTime += stat.totalTime; - runTime += stat.runTime; - } - var loadTime = totalTime - runTime; - var pie = new goog.ui.ServerChart( - goog.ui.ServerChart.ChartType.PIE, 500, 250); - pie.setMinValue(0); - pie.setMaxValue(totalTime); - pie.addDataSet([runTime, loadTime], 'ff9900'); - pie.setXLabels([ - 'Test execution (' + runTime + 'ms)', - 'Loading (' + loadTime + 'ms)']); - pie.render(this.statsEl_); -}; - - -/** - * Draws a pie chart showing the percentage of time spent running the tests - * compared to loading them etc. - * @private - */ -goog.testing.MultiTestRunner.prototype.drawWorstTestsTable_ = function() { - this.stats_.sort(function(a, b) { - return b['numFilesLoaded'] - a['numFilesLoaded']; - }); - - var tbody = goog.bind(this.dom_.createDom, this.dom_, 'tbody'); - var thead = goog.bind(this.dom_.createDom, this.dom_, 'thead'); - var tr = goog.bind(this.dom_.createDom, this.dom_, 'tr'); - var th = goog.bind(this.dom_.createDom, this.dom_, 'th'); - var td = goog.bind(this.dom_.createDom, this.dom_, 'td'); - var a = goog.bind(this.dom_.createDom, this.dom_, 'a'); - - var head = thead({'style': 'cursor: pointer'}, - tr(null, - th(null, ' '), - th(null, 'Test file'), - th('center', 'Num files loaded'), - th('center', 'Run time (ms)'), - th('center', 'Total time (ms)'))); - var body = tbody(); - var table = this.dom_.createDom('table', null, head, body); - - for (var i = 0; i < this.stats_.length; i++) { - var stat = this.stats_[i]; - body.appendChild(tr(null, - td('center', String(i + 1)), - td(null, a( - {'href': this.basePath_ + stat['testFile'], 'target': '_blank'}, - stat['testFile'])), - td('center', String(stat['numFilesLoaded'])), - td('center', String(stat['runTime'])), - td('center', String(stat['totalTime'])))); - } - - this.statsEl_.appendChild(table); - - this.tableSorter_.setDefaultSortFunction(goog.ui.TableSorter.numericSort); - this.tableSorter_.setSortFunction( - 1 /* test file name */, goog.ui.TableSorter.alphaSort); - this.tableSorter_.decorate(table); -}; - - -/** - * Clears the stats page. - * @private - */ -goog.testing.MultiTestRunner.prototype.clearStats_ = function() { - goog.dom.removeChildren(this.statsEl_); -}; - - -/** - * Updates the report's summary. - * @private - */ -goog.testing.MultiTestRunner.prototype.writeCurrentSummary_ = function() { - var total = this.activeTests_.length; - var executed = this.resultCount_; - var passes = this.passes_; - var duration = Math.round((goog.now() - this.startTime_) / 1000); - var text = executed + ' of ' + total + ' tests executed.<br>' + - passes + ' passed, ' + (executed - passes) + ' failed.<br>' + - 'Duration: ' + duration + 's.'; - this.reportEl_.firstChild.innerHTML = text; -}; - - -/** - * Adds a segment to the progress bar. - * @param {string} title Title for the segment. - * @param {*} success Whether the segment should indicate a success. - * @private - */ -goog.testing.MultiTestRunner.prototype.drawProgressSegment_ = - function(title, success) { - var part = this.progressRow_.cells[this.resultCount_ - 1]; - part.title = title + ' : ' + (success ? 'SUCCESS' : 'FAILURE'); - part.style.backgroundColor = success ? '#090' : '#900'; -}; - - -/** - * Draws a test result in the report pane. - * @param {string} test Test name. - * @param {*} success Whether the test succeeded. - * @param {string} report The report. - * @private - */ -goog.testing.MultiTestRunner.prototype.drawTestResult_ = function( - test, success, report) { - var text = goog.string.isEmpty(report) ? - 'No report for ' + test + '\n' : report; - var el = this.dom_.createDom('div'); - text = goog.string.htmlEscape(text).replace(/\n/g, '<br>'); - if (success) { - el.className = goog.getCssName('goog-testrunner-report-success'); - } else { - text += '<a href="' + this.basePath_ + test + - '">Run individually »</a><br> '; - el.className = goog.getCssName('goog-testrunner-report-failure'); - } - el.innerHTML = text; - this.reportEl_.appendChild(el); -}; - - -/** - * Returns the current timestamp. - * @return {string} HH:MM:SS. - * @private - */ -goog.testing.MultiTestRunner.prototype.getTimeStamp_ = function() { - var d = new Date; - return goog.string.padNumber(d.getHours(), 2) + ':' + - goog.string.padNumber(d.getMinutes(), 2) + ':' + - goog.string.padNumber(d.getSeconds(), 2); -}; - - -/** - * Trims a filename to be less than 35-characters, ensuring that we do not break - * a path part. - * @param {string} name The file name. - * @return {string} The shortened name. - * @private - */ -goog.testing.MultiTestRunner.prototype.trimFileName_ = function(name) { - if (name.length < 35) { - return name; - } - var parts = name.split('/'); - var result = ''; - while (result.length < 35 && parts.length > 0) { - result = '/' + parts.pop() + result; - } - return '...' + result; -}; - - -/** - * Shows the report and hides the log if the argument is true. - * @param {number} tab Which tab to show. - * @private - */ -goog.testing.MultiTestRunner.prototype.showTab_ = function(tab) { - var activeTabCssClass = goog.getCssName('goog-testrunner-activetab'); - if (tab == 0) { - this.logEl_.style.display = ''; - goog.dom.classes.add(this.logTabEl_, activeTabCssClass); - } else { - this.logEl_.style.display = 'none'; - goog.dom.classes.remove(this.logTabEl_, activeTabCssClass); - } - - if (tab == 1) { - this.reportEl_.style.display = ''; - goog.dom.classes.add(this.reportTabEl_, activeTabCssClass); - } else { - this.reportEl_.style.display = 'none'; - goog.dom.classes.remove(this.reportTabEl_, activeTabCssClass); - } - - if (tab == 2) { - this.statsEl_.style.display = ''; - goog.dom.classes.add(this.statsTabEl_, activeTabCssClass); - } else { - this.statsEl_.style.display = 'none'; - goog.dom.classes.remove(this.statsTabEl_, activeTabCssClass); - } -}; - - -/** - * Handles the start button being clicked. - * @param {goog.events.BrowserEvent} e The click event. - * @private - */ -goog.testing.MultiTestRunner.prototype.onStartClicked_ = function(e) { - this.start(); -}; - - -/** - * Handles the stop button being clicked. - * @param {goog.events.BrowserEvent} e The click event. - * @private - */ -goog.testing.MultiTestRunner.prototype.onStopClicked_ = function(e) { - this.stopped_ = true; - this.finish_(); -}; - - -/** - * Handles the log tab being clicked. - * @param {goog.events.BrowserEvent} e The click event. - * @private - */ -goog.testing.MultiTestRunner.prototype.onLogTabClicked_ = function(e) { - this.showTab_(0); -}; - - -/** - * Handles the log tab being clicked. - * @param {goog.events.BrowserEvent} e The click event. - * @private - */ -goog.testing.MultiTestRunner.prototype.onReportTabClicked_ = function(e) { - this.showTab_(1); -}; - - -/** - * Handles the stats tab being clicked. - * @param {goog.events.BrowserEvent} e The click event. - * @private - */ -goog.testing.MultiTestRunner.prototype.onStatsTabClicked_ = function(e) { - this.showTab_(2); -}; - - - -/** - * Class used to manage the interaction with a single iframe. - * @param {string} basePath The base path for tests. - * @param {number} timeoutMs The time to wait for the test to load and run. - * @param {boolean} verbosePasses Whether to show results for passes. - * @param {goog.dom.DomHelper=} opt_domHelper Optional dom helper. - * @constructor - * @extends {goog.ui.Component} - */ -goog.testing.MultiTestRunner.TestFrame = function( - basePath, timeoutMs, verbosePasses, opt_domHelper) { - goog.ui.Component.call(this, opt_domHelper); - - /** - * Base path where tests should be resolved from. - * @type {string} - * @private - */ - this.basePath_ = basePath; - - /** - * The timeout for the test. - * @type {number} - * @private - */ - this.timeoutMs_ = timeoutMs; - - /** - * Whether to show a summary for passing tests. - * @type {boolean} - * @private - */ - this.verbosePasses_ = verbosePasses; - - /** - * An event handler for handling events. - * @type {goog.events.EventHandler} - * @private - */ - this.eh_ = new goog.events.EventHandler(this); - -}; -goog.inherits(goog.testing.MultiTestRunner.TestFrame, goog.ui.Component); - - -/** - * Reference to the iframe. - * @type {HTMLIFrameElement} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.iframeEl_ = null; - - -/** - * Whether the iframe for the current test has loaded. - * @type {boolean} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.iframeLoaded_ = false; - - -/** - * The test file being run. - * @type {string} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.testFile_ = ''; - - -/** - * The report returned from the test. - * @type {string} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.report_ = ''; - - -/** - * The total time loading and running the test in milliseconds. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.totalTime_ = 0; - - -/** - * The actual runtime of the test in milliseconds. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.runTime_ = 0; - - -/** - * The number of files loaded by the test. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.numFilesLoaded_ = 0; - - -/** - * Whether the test was successful, null if no result has been returned yet. - * @type {?boolean} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.isSuccess_ = null; - - -/** - * Timestamp for the when the test was started. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.startTime_ = 0; - - -/** - * Timestamp for the last state, used to determine timeouts. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.lastStateTime_ = 0; - - -/** - * The state of the active test. - * @type {number} - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.currentState_ = 0; - - -/** @override */ -goog.testing.MultiTestRunner.TestFrame.prototype.disposeInternal = function() { - goog.testing.MultiTestRunner.TestFrame.superClass_.disposeInternal.call(this); - this.dom_.removeNode(this.iframeEl_); - this.eh_.dispose(); - this.iframeEl_ = null; -}; - - -/** - * Runs a test file in this test frame. - * @param {string} testFile The test to run. - */ -goog.testing.MultiTestRunner.TestFrame.prototype.runTest = function(testFile) { - this.lastStateTime_ = this.startTime_ = goog.now(); - - if (!this.iframeEl_) { - this.createIframe_(); - } - - this.iframeLoaded_ = false; - this.currentState_ = 0; - this.isSuccess_ = null; - this.report_ = ''; - this.testFile_ = testFile; - - try { - this.iframeEl_.src = this.basePath_ + testFile; - } catch (e) { - // Failures will trigger a JS exception on the local file system. - this.report_ = this.testFile_ + ' failed to load : ' + e.message; - this.isSuccess_ = false; - this.finish_(); - return; - } - - this.checkForCompletion_(); -}; - - -/** - * @return {string} The test file the TestFrame is running. - */ -goog.testing.MultiTestRunner.TestFrame.prototype.getTestFile = function() { - return this.testFile_; -}; - - -/** - * @return {Object} Stats about the test run. - */ -goog.testing.MultiTestRunner.TestFrame.prototype.getStats = function() { - return { - 'testFile': this.testFile_, - 'success': this.isSuccess_, - 'runTime': this.runTime_, - 'totalTime': this.totalTime_, - 'numFilesLoaded': this.numFilesLoaded_ - }; -}; - - -/** - * @return {string} The report for the test run. - */ -goog.testing.MultiTestRunner.TestFrame.prototype.getReport = function() { - return this.report_; -}; - - -/** - * @return {?boolean} Whether the test frame had a success. - */ -goog.testing.MultiTestRunner.TestFrame.prototype.isSuccess = function() { - return this.isSuccess_; -}; - - -/** - * Handles the TestFrame finishing a single test. - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.finish_ = function() { - this.totalTime_ = goog.now() - this.startTime_; - // TODO(user): Fire an event instead? - if (this.getParent() && this.getParent().processResult) { - this.getParent().processResult(this); - } -}; - - -/** - * Creates an iframe to run the tests in. For overriding in unit tests. - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.createIframe_ = function() { - this.iframeEl_ = - (/** @type {HTMLIFrameElement} */ this.dom_.createDom('iframe')); - this.getElement().appendChild(this.iframeEl_); - this.eh_.listen(this.iframeEl_, 'load', this.onIframeLoaded_); -}; - - -/** - * Handles the iframe loading. - * @param {goog.events.BrowserEvent} e The load event. - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.onIframeLoaded_ = function(e) { - this.iframeLoaded_ = true; -}; - - -/** - * Checks the active test for completion, keeping track of the tests' various - * execution stages. - * @private - */ -goog.testing.MultiTestRunner.TestFrame.prototype.checkForCompletion_ = - function() { - var js = goog.dom.getFrameContentWindow(this.iframeEl_); - switch (this.currentState_) { - case 0: - if (this.iframeLoaded_ && js['G_testRunner']) { - this.lastStateTime_ = goog.now(); - this.currentState_++; - } - break; - case 1: - if (js['G_testRunner']['isInitialized']()) { - this.lastStateTime_ = goog.now(); - this.currentState_++; - } - break; - case 2: - if (js['G_testRunner']['isFinished']()) { - var tr = js['G_testRunner']; - this.isSuccess_ = tr['isSuccess'](); - this.report_ = tr['getReport'](this.verbosePasses_); - this.runTime_ = tr['getRunTime'](); - this.numFilesLoaded_ = tr['getNumFilesLoaded'](); - this.finish_(); - return; - } - } - - // Check to see if the test has timed out. - if (goog.now() - this.lastStateTime_ > this.timeoutMs_) { - this.report_ = this.testFile_ + ' timed out ' + - goog.testing.MultiTestRunner.STATES[this.currentState_]; - this.isSuccess_ = false; - this.finish_(); - return; - } - - // Check again in 100ms. - goog.Timer.callOnce(this.checkForCompletion_, 100, this); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/objectpropertystring.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/objectpropertystring.js.svn-base deleted file mode 100644 index b8ee65a..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/objectpropertystring.js.svn-base +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Helper for passing property names as string literals in - * compiled test code. - * - */ - -goog.provide('goog.testing.ObjectPropertyString'); - - - -/** - * Object to pass a property name as a string literal and its containing object - * when the JSCompiler is rewriting these names. This should only be used in - * test code. - * - * @param {Object} object The containing object. - * @param {Object|string} propertyString Property name as a string literal. - * @constructor - */ -goog.testing.ObjectPropertyString = function(object, propertyString) { - this.object_ = object; - this.propertyString_ = /** @type {string} */ (propertyString); -}; - - -/** - * @type {Object} - * @private - */ -goog.testing.ObjectPropertyString.prototype.object_; - - -/** - * @type {string} - * @private - */ -goog.testing.ObjectPropertyString.prototype.propertyString_; - - -/** - * @return {Object} The object. - */ -goog.testing.ObjectPropertyString.prototype.getObject = function() { - return this.object_; -}; - - -/** - * @return {string} The property string. - */ -goog.testing.ObjectPropertyString.prototype.getPropertyString = function() { - return this.propertyString_; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetable.css.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetable.css.svn-base deleted file mode 100644 index 28056d0..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetable.css.svn-base +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2009 The Closure Library Authors. All Rights Reserved. - * - * Use of this source code is governed by the Apache License, Version 2.0. - * See the COPYING file for details. - */ - -/* Author: attila@google.com (Attila Bodis) */ -/* Author: nicksantos@google.com (Nick Santos) */ - -table.test-results { - font: 12px "Courier New", Courier, monospace; -} - -table.test-results thead th { - padding: 2px; - color: #fff; - background-color: #369; - text-align: center; -} - -table.test-results tbody td { - padding: 2px; - color: #333; - background-color: #ffc; - text-align: right; -} - -table.test-results tbody td.test-description { - text-align: left; -} - -table.test-results tbody td.test-average { - color: #000; - font-weight: bold; -} - -table.test-results tbody tr.test-suspicious td.test-standard-deviation { - color: #800; -} - -table.test-results tbody td.test-error { - color: #800; - font-weight: bold; - text-align: center; -} diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetable.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetable.js.svn-base deleted file mode 100644 index 7894837..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetable.js.svn-base +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview A table for showing the results of performance testing. - * - * {@see goog.testing.benchmark} for an easy way to use this functionality. - * - * @author attila@google.com (Attila Bodis) - * @author nicksantos@google.com (Nick Santos) - */ - -goog.provide('goog.testing.PerformanceTable'); - -goog.require('goog.dom'); -goog.require('goog.testing.PerformanceTimer'); - - - -/** - * A UI widget that runs performance tests and displays the results. - * @param {Element} root The element where the table should be attached. - * @param {goog.testing.PerformanceTimer=} opt_timer A timer to use for - * executing functions and profiling them. - * @param {number=} opt_precision Number of digits of precision to include in - * results. Defaults to 0. - * @constructor - */ -goog.testing.PerformanceTable = function(root, opt_timer, opt_precision) { - /** - * Where the table should be attached. - * @type {Element} - * @private - */ - this.root_ = root; - - /** - * Number of digits of precision to include in results. - * Defaults to 0. - * @type {number} - * @private - */ - this.precision_ = opt_precision || 0; - - var timer = opt_timer; - if (!timer) { - timer = new goog.testing.PerformanceTimer(); - timer.setNumSamples(5); - timer.setDiscardOutliers(true); - } - - /** - * A timer for running the tests. - * @type {goog.testing.PerformanceTimer} - * @private - */ - this.timer_ = timer; - - this.initRoot_(); -}; - - -/** - * @return {goog.testing.PerformanceTimer} The timer being used. - */ -goog.testing.PerformanceTable.prototype.getTimer = function() { - return this.timer_; -}; - - -/** - * Render the initial table. - * @private - */ -goog.testing.PerformanceTable.prototype.initRoot_ = function() { - this.root_.innerHTML = - '<table class="test-results" cellspacing="1">' + - ' <thead>' + - ' <tr>' + - ' <th rowspan="2">Test Description</th>' + - ' <th rowspan="2">Runs</th>' + - ' <th colspan="4">Results (ms)</th>' + - ' </tr>' + - ' <tr>' + - ' <th>Average</th>' + - ' <th>Std Dev</th>' + - ' <th>Minimum</th>' + - ' <th>Maximum</th>' + - ' </tr>' + - ' </thead>' + - ' <tbody>' + - ' </tbody>' + - '</table>'; -}; - - -/** - * @return {Element} The body of the table. - * @private - */ -goog.testing.PerformanceTable.prototype.getTableBody_ = function() { - return this.root_.getElementsByTagName(goog.dom.TagName.TBODY)[0]; -}; - - -/** - * Round to the specified precision. - * @param {number} num The number to round. - * @return {string} The rounded number, as a string. - * @private - */ -goog.testing.PerformanceTable.prototype.round_ = function(num) { - var factor = Math.pow(10, this.precision_); - return String(Math.round(num * factor) / factor); -}; - - -/** - * Run the given function with the performance timer, and show the results. - * @param {Function} fn The function to run. - * @param {string=} opt_desc A description to associate with this run. - */ -goog.testing.PerformanceTable.prototype.run = function(fn, opt_desc) { - var results = this.timer_.run(fn); - var average = results['average']; - var standardDeviation = results['standardDeviation']; - var isSuspicious = average < 0 || standardDeviation > average * .5; - var resultsRow = goog.dom.createDom('tr', null, - goog.dom.createDom('td', 'test-description', - opt_desc || 'No description'), - goog.dom.createDom('td', 'test-count', String(results['count'])), - goog.dom.createDom('td', 'test-average', this.round_(average)), - goog.dom.createDom('td', 'test-standard-deviation', - this.round_(standardDeviation)), - goog.dom.createDom('td', 'test-minimum', String(results['minimum'])), - goog.dom.createDom('td', 'test-maximum', String(results['maximum']))); - if (isSuspicious) { - resultsRow.className = 'test-suspicious'; - } - this.getTableBody_().appendChild(resultsRow); -}; - - -/** - * Report an error in the table. - * @param {*} reason The reason for the error. - */ -goog.testing.PerformanceTable.prototype.reportError = function(reason) { - this.getTableBody_().appendChild( - goog.dom.createDom('tr', null, - goog.dom.createDom('td', {'class': 'test-error', 'colSpan': 5}, - String(reason)))); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetimer.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetimer.js.svn-base deleted file mode 100644 index 599bf4a..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetimer.js.svn-base +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Performance timer. - * - * {@see goog.testing.benchmark} for an easy way to use this functionality. - * - * @author attila@google.com (Attila Bodis) - */ - -goog.provide('goog.testing.PerformanceTimer'); - -goog.require('goog.array'); -goog.require('goog.math'); - - - -/** - * Creates a performance timer that runs test functions a number of times to - * generate timing samples, and provides performance statistics (minimum, - * maximum, average, and standard deviation). - * @param {number=} opt_numSamples Number of times to run the test function; - * defaults to 10. - * @param {number=} opt_timeoutInterval Number of milliseconds after which the - * test is to be aborted; defaults to 5 seconds (5,000ms). - * @constructor - */ -goog.testing.PerformanceTimer = function(opt_numSamples, opt_timeoutInterval) { - /** - * Number of times the test function is to be run; defaults to 10. - * @type {number} - * @private - */ - this.numSamples_ = opt_numSamples || 10; - - /** - * Number of milliseconds after which the test is to be aborted; defaults to - * 5,000ms. - * @type {number} - * @private - */ - this.timeoutInterval_ = opt_timeoutInterval || 5000; - - /** - * Whether to discard outliers (i.e. the smallest and the largest values) - * from the sample set before computing statistics. Defaults to false. - * @type {boolean} - * @private - */ - this.discardOutliers_ = false; -}; - - -/** - * @return {number} The number of times the test function will be run. - */ -goog.testing.PerformanceTimer.prototype.getNumSamples = function() { - return this.numSamples_; -}; - - -/** - * Sets the number of times the test function will be run. - * @param {number} numSamples Number of times to run the test function. - */ -goog.testing.PerformanceTimer.prototype.setNumSamples = function(numSamples) { - this.numSamples_ = numSamples; -}; - - -/** - * @return {number} The number of milliseconds after which the test times out. - */ -goog.testing.PerformanceTimer.prototype.getTimeoutInterval = function() { - return this.timeoutInterval_; -}; - - -/** - * Sets the number of milliseconds after which the test times out. - * @param {number} timeoutInterval Timeout interval in ms. - */ -goog.testing.PerformanceTimer.prototype.setTimeoutInterval = function( - timeoutInterval) { - this.timeoutInterval_ = timeoutInterval; -}; - - -/** - * Sets whether to ignore the smallest and the largest values when computing - * stats. - * @param {boolean} discard Whether to discard outlier values. - */ -goog.testing.PerformanceTimer.prototype.setDiscardOutliers = function(discard) { - this.discardOutliers_ = discard; -}; - - -/** - * @return {boolean} Whether outlier values are discarded prior to computing - * stats. - */ -goog.testing.PerformanceTimer.prototype.isDiscardOutliers = function() { - return this.discardOutliers_; -}; - - -/** - * Executes the test function the required number of times (or until the - * test run exceeds the timeout interval, whichever comes first). Returns - * an object containing the following: - * <pre> - * { - * 'average': average execution time (ms) - * 'count': number of executions (may be fewer than expected due to timeout) - * 'maximum': longest execution time (ms) - * 'minimum': shortest execution time (ms) - * 'standardDeviation': sample standard deviation (ms) - * 'total': total execution time (ms) - * } - * </pre> - * - * @param {Function} testFn Test function whose performance is to - * be measured. - * @return {Object} Object containing performance stats. - */ -goog.testing.PerformanceTimer.prototype.run = function(testFn) { - var samples = []; - var testStart = goog.now(); - var totalRunTime = 0; - - for (var i = 0; i < this.numSamples_ && totalRunTime <= this.timeoutInterval_; - i++) { - var sampleStart = goog.now(); - testFn(); - var sampleEnd = goog.now(); - samples[i] = sampleEnd - sampleStart; - totalRunTime = sampleEnd - testStart; - } - - if (this.discardOutliers_ && samples.length > 2) { - goog.array.remove(samples, Math.min.apply(null, samples)); - goog.array.remove(samples, Math.max.apply(null, samples)); - } - - return { - 'average': goog.math.average.apply(null, samples), - 'count': i, - 'maximum': Math.max.apply(null, samples), - 'minimum': Math.min.apply(null, samples), - 'standardDeviation': goog.math.standardDeviation.apply(null, samples), - 'total': goog.math.sum.apply(null, samples) - }; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetimer_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetimer_test.html.svn-base deleted file mode 100644 index 58e863d..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/performancetimer_test.html.svn-base +++ /dev/null @@ -1,102 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- -Author: attila@google.com (Attila Bodis) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> - <title>Closure Unit Tests - goog.testing.PerformanceTimer</title> - <script src="../base.js"></script> - <script> - goog.require('goog.dom'); - goog.require('goog.testing.MockClock'); - goog.require('goog.testing.PerformanceTimer'); - goog.require('goog.testing.jsunit'); - </script> -</head> -<body> - <div id="sandbox"></div> - <script> - var mockClock; - var sandbox = document.getElementById('sandbox'); - var timer; - - // Fast test function, pretty much guaranteed to run in under 5,000ms. - function fastTestFunction() { - for (var i = 0; i < 10; i++) { - var div = document.createElement('div'); - div.innerHTML = 'Div no. ' + i; - sandbox.appendChild(div); - } - } - - function setUp() { - mockClock = new goog.testing.MockClock(false); - timer = new goog.testing.PerformanceTimer(); - } - - function tearDown() { - mockClock.dispose(); - timer = null; - goog.dom.removeChildren(sandbox); - } - - function testConstructor() { - assertTrue('Timer must be an instance of goog.testing.PerformanceTimer', - timer instanceof goog.testing.PerformanceTimer); - assertEquals('Timer must collect the default number of samples', 10, - timer.getNumSamples()); - assertEquals('Timer must have the default timeout interval', 5000, - timer.getTimeoutInterval()); - } - - function testRun() { - // Fast test function should complete successfully in under 5 seconds... - var results = timer.run(fastTestFunction); - - assertNotNull('Results must be available', - results); - assertTrue('Average must be a nonnegative number', - results['average'] >= 0); - assertEquals('Count must be as expected', 10, - results['count']); - assertTrue('Maximum must be a nonnegative number', - results['maximum'] >= 0); - assertTrue('Mimimum must be a nonnegative number', - results['minimum'] >= 0); - assertTrue('Standard deviation must be a nonnegative number', - results['standardDeviation'] >= 0); - assertTrue('Total must be a nonnegative number', - results['total'] >= 0); - assertTrue('Average must be between minimum and maximum', - results['minimum'] <= results['average'] && - results['average'] <= results['maximum']); - } - - function testTimeout() { - mockClock.install(); - var count = 0; - - var testFunction = function() { - mockClock.tick(100); - ++count; - }; - - timer.setNumSamples(200); - timer.setTimeoutInterval(2500); - var results = timer.run(testFunction); - - assertNotNull('Results must be available', results); - assertEquals('Count is wrong', count, results['count']); - assertTrue('Count must less than expected', - results['count'] < timer.getNumSamples()); - } - </script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/propertyreplacer.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/propertyreplacer.js.svn-base deleted file mode 100644 index 305e2b0..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/propertyreplacer.js.svn-base +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Helper class for creating stubs for testing. - * - */ - -goog.provide('goog.testing.PropertyReplacer'); - -goog.require('goog.userAgent'); - - - -/** - * Helper class for stubbing out variables and object properties for unit tests. - * This class can change the value of some variables before running the test - * cases, and to reset them in the tearDown phase. - * See googletest.StubOutForTesting as an analogy in Python: - * http://protobuf.googlecode.com/svn/trunk/python/stubout.py - * - * Example usage: - * <pre>var stubs = new goog.testing.PropertyReplacer(); - * - * function setUp() { - * // Mock functions used in all test cases. - * stubs.set(Math, 'random', function() { - * return 4; // Chosen by fair dice roll. Guaranteed to be random. - * }); - * } - * - * function tearDown() { - * stubs.reset(); - * } - * - * function testThreeDice() { - * // Mock a constant used only in this test case. - * stubs.set(goog.global, 'DICE_COUNT', 3); - * assertEquals(12, rollAllDice()); - * }</pre> - * - * Constraints on altered objects: - * <ul> - * <li>DOM subclasses aren't supported. - * <li>The value of the objects' constructor property must either be equal to - * the real constructor or kept untouched. - * </ul> - * - * @constructor - */ -goog.testing.PropertyReplacer = function() { - /** - * Stores the values changed by the set() method in chronological order. - * Its items are objects with 3 fields: 'object', 'key', 'value'. The - * original value for the given key in the given object is stored under the - * 'value' key. - * @type {Array.<Object>} - * @private - */ - this.original_ = []; -}; - - -/** - * Indicates that a key didn't exist before having been set by the set() method. - * @type {Object} - * @private - */ -goog.testing.PropertyReplacer.NO_SUCH_KEY_ = {}; - - -/** - * Tells if the given key exists in the object. Ignores inherited fields. - * @param {Object|Function} obj The JavaScript or native object or function - * whose key is to be checked. - * @param {string} key The key to check. - * @return {boolean} Whether the object has the key as own key. - * @private - */ -goog.testing.PropertyReplacer.hasKey_ = function(obj, key) { - if (!(key in obj)) { - return false; - } - // hasOwnProperty is only reliable with JavaScript objects. It returns false - // for built-in DOM attributes. - if (Object.prototype.hasOwnProperty.call(obj, key)) { - return true; - } - // In all browsers except Opera obj.constructor never equals to Object if - // obj is an instance of a native class. In Opera we have to fall back on - // examining obj.toString(). - if (obj.constructor == Object && - (!goog.userAgent.OPERA || - Object.prototype.toString.call(obj) == '[object Object]')) { - return false; - } - try { - // Firefox hack to consider "className" part of the HTML elements or - // "body" part of document. Although they are defined in the prototype of - // HTMLElement or Document, accessing them this way throws an exception. - // <pre> - // var dummy = document.body.constructor.prototype.className - // [Exception... "Cannot modify properties of a WrappedNative"] - // </pre> - var dummy = obj.constructor.prototype[key]; - } catch (e) { - return true; - } - return !(key in obj.constructor.prototype); -}; - - -/** - * Deletes a key from an object. Sets it to undefined or empty string if the - * delete failed. - * @param {Object|Function} obj The object or function to delete a key from. - * @param {string} key The key to delete. - * @private - */ -goog.testing.PropertyReplacer.deleteKey_ = function(obj, key) { - try { - delete obj[key]; - // Delete has no effect for built-in properties of DOM nodes in FF. - if (!goog.testing.PropertyReplacer.hasKey_(obj, key)) { - return; - } - } catch (e) { - // IE throws TypeError when trying to delete properties of native objects - // (e.g. DOM nodes or window), even if they have been added by JavaScript. - } - - obj[key] = undefined; - if (obj[key] == 'undefined') { - // Some properties such as className in IE are always evaluated as string - // so undefined will become 'undefined'. - obj[key] = ''; - } -}; - - -/** - * Adds or changes a value in an object while saving its original state. - * @param {Object|Function} obj The JavaScript or native object or function to - * alter. See the constraints in the class description. - * @param {string} key The key to change the value for. - * @param {*} value The new value to set. - */ -goog.testing.PropertyReplacer.prototype.set = function(obj, key, value) { - var origValue = goog.testing.PropertyReplacer.hasKey_(obj, key) ? obj[key] : - goog.testing.PropertyReplacer.NO_SUCH_KEY_; - this.original_.push({object: obj, key: key, value: origValue}); - obj[key] = value; -}; - - -/** - * Changes an existing value in an object to another one of the same type while - * saving its original state. The advantage of {@code replace} over {@link #set} - * is that {@code replace} protects against typos and erroneously passing tests - * after some members have been renamed during a refactoring. - * @param {Object|Function} obj The JavaScript or native object or function to - * alter. See the constraints in the class description. - * @param {string} key The key to change the value for. It has to be present - * either in {@code obj} or in its prototype chain. - * @param {*} value The new value to set. It has to have the same type as the - * original value. The types are compared with {@link goog.typeOf}. - * @throws {Error} In case of missing key or type mismatch. - */ -goog.testing.PropertyReplacer.prototype.replace = function(obj, key, value) { - if (!(key in obj)) { - throw Error('Cannot replace missing property "' + key + '" in ' + obj); - } - if (goog.typeOf(obj[key]) != goog.typeOf(value)) { - throw Error('Cannot replace property "' + key + '" in ' + obj + - ' with a value of different type'); - } - this.set(obj, key, value); -}; - - -/** - * Builds an object structure for the provided namespace path. Doesn't - * overwrite those prefixes of the path that are already objects or functions. - * @param {string} path The path to create or alter, e.g. 'goog.ui.Menu'. - * @param {*} value The value to set. - */ -goog.testing.PropertyReplacer.prototype.setPath = function(path, value) { - var parts = path.split('.'); - var obj = goog.global; - for (var i = 0; i < parts.length - 1; i++) { - var part = parts[i]; - if (part == 'prototype' && !obj[part]) { - throw Error('Cannot set the prototype of ' + parts.slice(0, i).join('.')); - } - if (!goog.isObject(obj[part]) && !goog.isFunction(obj[part])) { - this.set(obj, part, {}); - } - obj = obj[part]; - } - this.set(obj, parts[parts.length - 1], value); -}; - - -/** - * Deletes the key from the object while saving its original value. - * @param {Object|Function} obj The JavaScript or native object or function to - * alter. See the constraints in the class description. - * @param {string} key The key to delete. - */ -goog.testing.PropertyReplacer.prototype.remove = function(obj, key) { - if (goog.testing.PropertyReplacer.hasKey_(obj, key)) { - this.original_.push({object: obj, key: key, value: obj[key]}); - goog.testing.PropertyReplacer.deleteKey_(obj, key); - } -}; - - -/** - * Resets all changes made by goog.testing.PropertyReplacer.prototype.set. - */ -goog.testing.PropertyReplacer.prototype.reset = function() { - for (var i = this.original_.length - 1; i >= 0; i--) { - var original = this.original_[i]; - if (original.value == goog.testing.PropertyReplacer.NO_SUCH_KEY_) { - goog.testing.PropertyReplacer.deleteKey_(original.object, original.key); - } else { - original.object[original.key] = original.value; - } - delete this.original_[i]; - } - this.original_.length = 0; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/propertyreplacer_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/propertyreplacer_test.html.svn-base deleted file mode 100644 index 6ad2eff..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/propertyreplacer_test.html.svn-base +++ /dev/null @@ -1,368 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.PropertyReplacer</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.PropertyReplacer'); - goog.require('goog.testing.asserts'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - -// Test PropertyReplacer with JavaScript objects. -function testSetJsProperties() { - var stubs = new goog.testing.PropertyReplacer(); - var x = {a: 1, b: undefined}; - - // Setting simple values. - stubs.set(x, 'num', 1); - assertEquals('x.num = 1', 1, x.num); - stubs.set(x, 'undef', undefined); - assertTrue('x.undef = undefined', 'undef' in x && x.undef === undefined); - stubs.set(x, 'null', null); - assertTrue('x["null"] = null', x['null'] === null); - - // Setting a simple value that existed originally. - stubs.set(x, 'b', null); - assertTrue('x.b = null', x.b === null); - - // Setting a complex value. - stubs.set(x, 'obj', {}); - assertEquals('x.obj = {}', 'object', typeof x.obj); - stubs.set(x.obj, 'num', 2); - assertEquals('x.obj.num = 2', 2, x.obj.num); - - // Overwriting a leaf. - stubs.set(x.obj, 'num', 3); - assertEquals('x.obj.num = 3', 3, x.obj.num); - - // Overwriting a non-leaf. - stubs.set(x, 'obj', {}); - assertFalse('x.obj = {} again', 'num' in x.obj); - - // Setting a function. - stubs.set(x, 'func', function(n) { return n + 1; }); - assertEquals('x.func = lambda n: n+1', 11, x.func(10)); - - // Setting a constructor and a prototype method. - stubs.set(x, 'Class', function(num) { this.num = num; }); - stubs.set(x.Class.prototype, 'triple', function() { return this.num * 3; }); - assertEquals('prototype method', 12, (new x.Class(4)).triple()); - - // Cleaning up with UnsetAll() twice. The second run should have no effect. - for (var i = 0; i < 2; i++) { - stubs.reset(); - assertEquals('x.a preserved', 1, x.a); - assertTrue('x.b reset', 'b' in x && x.b === undefined); - assertFalse('x.num removed', 'num' in x); - assertFalse('x.undef removed', 'undef' in x); - assertFalse('x["null"] removed', 'null' in x); - assertFalse('x.obj removed', 'obj' in x); - assertFalse('x.func removed', 'func' in x); - assertFalse('x.Class removed', 'Class' in x); - } -} - -// Test removing JavaScript object properties. -function testRemoveJsProperties() { - var stubs = new goog.testing.PropertyReplacer(); - var orig = {'a': 1, 'b': undefined}; - var x = {'a': 1, 'b': undefined}; - - stubs.remove(x, 'a'); - assertFalse('x.a removed', 'a' in x); - assertTrue('x.b not removed', 'b' in x); - stubs.reset(); - assertObjectEquals('x.a reset', x, orig); - - stubs.remove(x, 'b'); - assertFalse('x.b removed', 'b' in x); - stubs.reset(); - assertObjectEquals('x.b reset', x, orig); - - stubs.set(x, 'c', 2); - stubs.remove(x, 'c'); - assertObjectEquals('x.c added then removed', x, orig); - stubs.reset(); - assertObjectEquals('x.c reset', x, orig); - - stubs.remove(x, 'b'); - stubs.set(x, 'b', undefined); - assertObjectEquals('x.b removed then added', x, orig); - stubs.reset(); - assertObjectEquals('x.b reset', x, orig); - - stubs.remove(x, 'd'); - assertObjectEquals('removing non-existing key', x, orig); - stubs.reset(); - assertObjectEquals('reset removing non-existing key', x, orig); -} - -// Test PropertyReplacer with prototype chain. -function testPrototype() { - var stubs = new goog.testing.PropertyReplacer(); - - // Simple inheritance. - var a = {a: 0}; - function B() {}; - B.prototype = a; - var b = new B(); - - stubs.set(a, 0, 1); - stubs.set(b, 0, 2); - stubs.reset(); - assertEquals('a.a == 0', 0, a['a']); - assertEquals('b.a == 0', 0, b['a']); - - // Inheritance with goog.inherits. - var c = {a: 0}; - function C() {}; - C.prototype = c; - function D() {}; - goog.inherits(D, C); - var d = new D(); - - var stubs = new goog.testing.PropertyReplacer(); - stubs.set(c, 'a', 1); - stubs.set(d, 'a', 2); - stubs.reset(); - assertEquals('c.a == 0', 0, c['a']); - assertEquals('d.a == 0', 0, d['a']); - - // Setting prototype fields. - stubs.set(B.prototype, 'c', 'z'); - assertEquals('b.c=="z"', 'z', b.c); - stubs.reset(); - assertFalse('b.c deleted', 'c' in b); - - // Setting Object.prototype's fields. - stubs.set(Object.prototype, 'one', 1); - assertEquals('b.one==1', 1, b.one); - stubs.reset(); - assertFalse('b.one deleted', 'one' in b); - - stubs.set(Object.prototype, 'two', 2); - stubs.remove(b, 'two'); - assertEquals('b.two==2', 2, b.two); - stubs.remove(Object.prototype, 'two'); - assertFalse('b.two deleted', 'two' in b); - stubs.reset(); - assertFalse('Object prototype reset', 'two' in b); -} - -// Test replacing function properties. -function testFunctionProperties() { - var stubs = new goog.testing.PropertyReplacer(); - stubs.set(Array, 'x', 1); - assertEquals('Array.x==1', 1, Array.x); - stubs.reset(); - assertFalse('Array.x deleted', 'x' in Array); - - stubs.set(Math.random, 'x', 1); - assertEquals('Math.random.x==1', 1, Math.random.x); - stubs.reset(); - assertFalse('Math.random.x deleted', 'x' in Math.random); -} - -// Test the hasKey_ private method. -function testHasKey() { - f = goog.testing.PropertyReplacer.hasKey_; - - assertFalse('{}.a', f({}, 'a')); - assertTrue('{a:0}.a', f({a: 0}, 'a')); - - function C() {}; - C.prototype.a = 0; - assertFalse('C.prototype.a set, is C.a own?', f(C, 'a')); - assertTrue('C.prototype.a', f(C.prototype, 'a')); - assertFalse('C.a not set', f(C, 'a')); - C.a = 0; - assertTrue('C.a set', f(C, 'a')); - - var c = new C(); - assertFalse('C().a, inherited', f(c, 'a')); - c.a = 0; - assertTrue('C().a, own', f(c, 'a')); - - assertFalse('window, invalid key', f(window, 'no such key')); - assertTrue('window, global variable', f(window, 'goog')); - assertTrue('window, build-in key', f(window, 'location')) - - assertFalse('document, invalid key', f(document, 'no such key')); - assertTrue('document.body', f(document, 'body')); - - var div = document.createElement('div'); - assertFalse('div, invalid key', f(div, 'no such key')); - assertTrue('div.className', f(div, 'className')); - div['a'] = 0; - assertTrue('div, key added by JS', f(div, 'a')); - - assertFalse('Date().getTime', f(new Date(), 'getTime')); - assertTrue('Date.prototype.getTime', f(Date.prototype, 'getTime')); - - assertFalse('Math, invalid key', f(Math, 'no such key')); - assertTrue('Math.random', f(Math, 'random')); - - function Parent() {}; - Parent.prototype.a = 0; - function Child() {}; - goog.inherits(Child, Parent); - assertFalse('goog.inherits, parent prototype', f(new Child, 'a')); - Child.prototype.a = 1; - assertFalse('goog.inherits, child prototype', f(new Child, 'a')); - - function OverwrittenProto() {}; - OverwrittenProto.prototype = {a: 0}; - assertFalse(f(new OverwrittenProto, 'a')); -} - -// Test PropertyReplacer with DOM objects' built in attributes. -function testDomBuiltInAttributes() { - var div = document.createElement('div'); - div.id = 'old-id'; - - var stubs = new goog.testing.PropertyReplacer(); - stubs.set(div, 'id', 'new-id'); - stubs.set(div, 'className', 'test-class'); - assertEquals('div.id == "new-id"', 'new-id', div.id); - assertEquals('div.className == "test-class"', 'test-class', div.className); - - stubs.remove(div, 'className'); - // '' in Firefox, undefined in Chrome. - assertEvaluatesToFalse('div.className is empty', div.className); - - stubs.reset(); - assertEquals('div.id == "old-id"', 'old-id', div.id); - assertEquals('div.name == ""', '', div.className); -} - -// Test PropertyReplacer with DOM objects' custom attributes. -function testDomCustomAttributes() { - var div = document.createElement('div'); - div.attr1 = 'old'; - - var stubs = new goog.testing.PropertyReplacer(); - stubs.set(div, 'attr1', 'new'); - stubs.set(div, 'attr2', 'new'); - assertEquals('div.attr1 == "new"', 'new', div.attr1); - assertEquals('div.attr2 == "new"', 'new', div.attr2); - - stubs.set(div, 'attr3', 'new'); - stubs.remove(div, 'attr3'); - assertEquals('div.attr3 == undefined', undefined, div.attr3); - - stubs.reset(); - assertEquals('div.attr1 == "old"', 'old', div.attr1); - assertEquals('div.attr2 == undefined', undefined, div.attr2); -} - -// Test PropertyReplacer overriding Math.random. -function testMathRandom() { - var stubs = new goog.testing.PropertyReplacer(); - stubs.set(Math, 'random', function() { return -1; }); - assertEquals('mocked Math.random', -1, Math.random()); - - stubs.reset(); - assertNotEquals('original Math.random', -1, Math.random()); -} - -// Tests the replace method of PropertyReplacer. -function testReplace() { - var stubs = new goog.testing.PropertyReplacer(); - function C() { - this.a = 1; - }; - C.prototype.b = 1; - C.prototype.toString = function() { - return 'obj'; - }; - var obj = new C(); - - stubs.replace(obj, 'a', 2); - assertEquals('successfully replaced the own property of an object', 2, obj.a); - - stubs.replace(obj, 'b', 2); - assertEquals('successfully replaced the property in the prototype', 2, obj.b); - - var error = assertThrows('cannot replace missing key', - goog.bind(stubs.replace, stubs, obj, 'unknown', 1)); - // Using assertContains instead of assertEquals because Opera 10.0 adds - // the stack trace to the error message. - assertEquals('error message for missing key', - 'Cannot replace missing property "unknown" in obj', error.message); - assertFalse('object not touched', 'unknown' in obj); - - var error = assertThrows('cannot change value type', - goog.bind(stubs.replace, stubs, obj, 'a', '3')); - assertContains('error message for type mismatch', - 'Cannot replace property "a" in obj with a value of different type', - error.message); -} - -// Tests altering complete namespace paths. -function testSetPath() { - goog.global.a = {b: {}}; - var stubs = new goog.testing.PropertyReplacer(); - - stubs.setPath('a.b.c.d', 1); - assertObjectEquals('a.b.c.d=1', {b: {c: {d: 1}}}, goog.global.a); - stubs.setPath('a.b.e', 2); - assertObjectEquals('a.b.e=2', {b: {c: {d: 1}, e: 2}}, goog.global.a); - stubs.setPath('a.f', 3); - assertObjectEquals('a.f=3', {b: {c: {d: 1}, e: 2}, f: 3}, goog.global.a); - stubs.setPath('a.f.g', 4); - assertObjectEquals('a.f.g=4', {b: {c: {d: 1}, e: 2}, f: {g: 4}}, - goog.global.a); - stubs.setPath('a', 5); - assertEquals('a=5', 5, goog.global.a); - - stubs.setPath('x.y.z', 5); - assertObjectEquals('x.y.z=5', {y: {z: 5}}, goog.global.x); - - stubs.reset(); - assertObjectEquals('a.* reset', {b: {}}, goog.global.a); - // NOTE: it's impossible to delete global variables in Internet Explorer, - // so ('x' in goog.global) would be true. - assertUndefined('x.* reset', goog.global.x); -} - -// Tests altering paths with functions in them. -function testSetPathWithFunction() { - var f = function() {}; - goog.global.a = {b: f}; - var stubs = new goog.testing.PropertyReplacer(); - - stubs.setPath('a.b.c', 1); - assertEquals('a.b.c=1, f kept', f, goog.global.a.b); - assertEquals('a.b.c=1, c set', 1, goog.global.a.b.c); - - stubs.setPath('a.b.prototype.d', 2); - assertEquals('a.b.prototype.d=2, b kept', f, goog.global.a.b); - assertEquals('a.b.prototype.d=2, c kept', 1, goog.global.a.b.c); - assertFalse('a.b.prototype.d=2, a.b.d not set', 'd' in goog.global.a.b); - assertTrue('a.b.prototype.d=2, proto set', 'd' in goog.global.a.b.prototype); - assertEquals('a.b.prototype.d=2, d set', 2, new goog.global.a.b().d); - - var invalidSetPath = function() { - stubs.setPath('a.prototype.e', 3); - }; - assertThrows('setting the prototype of a non-function', invalidSetPath); - - stubs.reset(); - assertObjectEquals('a.b.c reset', {b: f}, goog.global.a); - assertObjectEquals('a.b.prototype reset', {}, goog.global.a.b.prototype); -} - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/pseudorandom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/pseudorandom.js.svn-base deleted file mode 100644 index 23ea0ef..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/pseudorandom.js.svn-base +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright 2011 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview PseudoRandom provides a mechanism for generating deterministic - * psuedo random numbers based on a seed. Based on the Park-Miller algorithm. - * See http://dx.doi.org/10.1145%2F63039.63042 for details. - * - */ - -goog.provide('goog.testing.PseudoRandom'); - -goog.require('goog.Disposable'); - - - -/** - * Class for unit testing code that uses Math.random. Generates deterministic - * random numbers. - * - * @param {number=} opt_seed The seed to use. - * @param {boolean=} opt_install Whether to install the PseudoRandom at - * construction time. - * @extends {goog.Disposable} - * @constructor - */ -goog.testing.PseudoRandom = function(opt_seed, opt_install) { - goog.Disposable.call(this); - - if (!goog.isDef(opt_seed)) { - opt_seed = goog.testing.PseudoRandom.seedUniquifier_++ + goog.now(); - } - this.seed(opt_seed); - - if (opt_install) { - this.install(); - } -}; -goog.inherits(goog.testing.PseudoRandom, goog.Disposable); - - -/** - * Helps create a unique seed. - * @type {number} - * @private - */ -goog.testing.PseudoRandom.seedUniquifier_ = 0; - - -/** - * Constant used as part of the algorithm. - * @type {number} - */ -goog.testing.PseudoRandom.A = 48271; - - -/** - * Constant used as part of the algorithm. 2^31 - 1. - * @type {number} - */ -goog.testing.PseudoRandom.M = 2147483647; - - -/** - * Constant used as part of the algorithm. It is equal to M / A. - * @type {number} - */ -goog.testing.PseudoRandom.Q = 44488; - - -/** - * Constant used as part of the algorithm. It is equal to M % A. - * @type {number} - */ -goog.testing.PseudoRandom.R = 3399; - - -/** - * Constant used as part of the algorithm to get values from range [0, 1). - * @type {number} - */ -goog.testing.PseudoRandom.ONE_OVER_M_MINUS_ONE = - 1.0 / (goog.testing.PseudoRandom.M - 1); - - -/** - * The seed of the random sequence and also the next returned value (before - * normalization). Must be between 1 and M - 1 (inclusive). - * @type {number} - * @private - */ -goog.testing.PseudoRandom.prototype.seed_ = 1; - - -/** - * Whether this PseudoRandom has been installed. - * @type {boolean} - * @private - */ -goog.testing.PseudoRandom.prototype.installed_; - - -/** - * The original Math.random function. - * @type {function(): number} - * @private - */ -goog.testing.PseudoRandom.prototype.mathRandom_; - - -/** - * Installs this PseudoRandom as the system number generator. - */ -goog.testing.PseudoRandom.prototype.install = function() { - if (!this.installed_) { - this.mathRandom_ = Math.random; - Math.random = goog.bind(this.random, this); - this.installed_ = true; - } -}; - - -/** @override */ -goog.testing.PseudoRandom.prototype.disposeInternal = function() { - goog.testing.PseudoRandom.superClass_.disposeInternal.call(this); - this.uninstall(); -}; - - -/** - * Uninstalls the PseudoRandom. - */ -goog.testing.PseudoRandom.prototype.uninstall = function() { - if (this.installed_) { - Math.random = this.mathRandom_; - this.installed_ = false; - } -}; - - -/** - * Seed the generator. - * - * @param {number=} seed The seed to use. - */ -goog.testing.PseudoRandom.prototype.seed = function(seed) { - this.seed_ = seed % (goog.testing.PseudoRandom.M - 1); - if (this.seed_ <= 0) { - this.seed_ += goog.testing.PseudoRandom.M - 1; - } -}; - - -/** - * @return {number} The next number in the sequence. - */ -goog.testing.PseudoRandom.prototype.random = function() { - var hi = Math.floor(this.seed_ / goog.testing.PseudoRandom.Q); - var lo = this.seed_ % goog.testing.PseudoRandom.Q; - var test = goog.testing.PseudoRandom.A * lo - - goog.testing.PseudoRandom.R * hi; - if (test > 0) { - this.seed_ = test; - } else { - this.seed_ = test + goog.testing.PseudoRandom.M; - } - return (this.seed_ - 1) * goog.testing.PseudoRandom.ONE_OVER_M_MINUS_ONE; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/pseudorandom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/pseudorandom_test.html.svn-base deleted file mode 100644 index 62d0261..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/pseudorandom_test.html.svn-base +++ /dev/null @@ -1,98 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2009 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.PseudoRandom</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.PseudoRandom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - - function runFairnessTest(sides, rolls, chiSquareLimit) { - // Initialize the count table for dice rolls. - var counts = []; - for (var i = 0; i < sides; ++i) { - counts[i] = 0; - } - // Roll the dice many times and count the results. - for (var i = 0; i < rolls; ++i) { - ++counts[Math.floor(Math.random() * sides)]; - } - // If the dice is fair, we expect a uniform distribution. - var expected = rolls / sides; - // Pearson's chi-square test for a distribution fit. - var chiSquare = 0 - for (var i = 0; i < sides; ++i) { - chiSquare += (counts[i] - expected) * (counts[i] - expected) / expected; - } - assert('Chi-square test for a distribution fit failed', - chiSquare < chiSquareLimit); - } - - function testInstall() { - var random = new goog.testing.PseudoRandom(); - var originalRandom = Math.random; - - assertFalse(!!random.installed_); - - random.install(); - assertTrue(random.installed_); - assertNotEquals(Math.random, originalRandom); - - random.uninstall(); - assertFalse(random.installed_); - assertEquals(originalRandom, Math.random); - } - - function testBounds() { - var random = new goog.testing.PseudoRandom(); - random.install(); - - for (var i = 0; i < 100000; ++i) { - var value = Math.random(); - assert('Random value out of bounds', value >= 0 && value < 1); - } - - random.uninstall(); - } - - function testFairness() { - var random = new goog.testing.PseudoRandom(0, true); - - // Chi-square statistics: p-value = 0.05, df = 5, limit = 11.07. - runFairnessTest(6, 100000, 11.07); - // Chi-square statistics: p-value = 0.05, df = 100, limit = 124.34. - runFairnessTest(101, 100000, 124.34); - - random.uninstall(); - } - - function testReseed() { - var random = new goog.testing.PseudoRandom(100, true); - - var sequence = []; - for (var i = 0; i < 64000; ++i) { - sequence.push(Math.random()); - } - - random.seed(100); - for (var i = 0; i < sequence.length; ++i) { - assertEquals(sequence[i], Math.random()); - } - - random.uninstall(); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/recordfunction.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/recordfunction.js.svn-base deleted file mode 100644 index ae10c28..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/recordfunction.js.svn-base +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Helper class for recording the calls of a function. - * - * Example: - * <pre> - * var stubs = new goog.testing.PropertyReplacer(); - * - * function tearDown() { - * stubs.reset(); - * } - * - * function testShuffle() { - * stubs.set(Math, 'random', goog.testing.recordFunction(Math.random)); - * var arr = shuffle([1, 2, 3, 4, 5]); - * assertSameElements([1, 2, 3, 4, 5], arr); - * assertEquals(4, Math.random.getCallCount()); - * } - * - * function testOpenDialog() { - * stubs.set(goog.ui, 'Dialog', - * goog.testing.recordConstructor(goog.ui.Dialog)); - * openConfirmDialog(); - * var lastDialogInstance = goog.ui.Dialog.getLastCall().getThis(); - * assertEquals('confirm', lastDialogInstance.getTitle()); - * } - * </pre> - * - */ - -goog.provide('goog.testing.FunctionCall'); -goog.provide('goog.testing.recordConstructor'); -goog.provide('goog.testing.recordFunction'); - - -/** - * Wraps the function into another one which calls the inner function and - * records its calls. The recorded function will have 3 static methods: - * {@code getCallCount}, {@code getCalls} and {@code getLastCall} but won't - * inherit the original function's prototype and static fields. - * - * @param {!Function=} opt_f The function to wrap and record. Defaults to - * {@link goog.nullFunction}. - * @return {!Function} The wrapped function. - */ -goog.testing.recordFunction = function(opt_f) { - var f = opt_f || goog.nullFunction; - var calls = []; - - function recordedFunction() { - try { - var ret = f.apply(this, arguments); - calls.push(new goog.testing.FunctionCall(f, this, arguments, ret, null)); - return ret; - } catch (err) { - calls.push(new goog.testing.FunctionCall(f, this, arguments, undefined, - err)); - throw err; - } - } - - /** - * @return {number} Total number of calls. - */ - recordedFunction.getCallCount = function() { - return calls.length; - }; - - /** - * @return {!Array.<!goog.testing.FunctionCall>} All calls of the recorded - * function. - */ - recordedFunction.getCalls = function() { - return calls; - }; - - /** - * @return {goog.testing.FunctionCall} Last call of the recorded function or - * null if it hasn't been called. - */ - recordedFunction.getLastCall = function() { - return calls[calls.length - 1] || null; - }; - - /** - * Returns and removes the last call of the recorded function. - * @return {goog.testing.FunctionCall} Last call of the recorded function or - * null if it hasn't been called. - */ - recordedFunction.popLastCall = function() { - return calls.pop() || null; - }; - - /** - * Resets the recorded function and removes all calls. - */ - recordedFunction.reset = function() { - calls.length = 0; - }; - - return recordedFunction; -}; - - -/** - * Same as {@link goog.testing.recordFunction} but the recorded function will - * have the same prototype and static fields as the original one. It can be - * used with constructors. - * - * @param {!Function} ctor The function to wrap and record. - * @return {!Function} The wrapped function. - */ -goog.testing.recordConstructor = function(ctor) { - var recordedConstructor = goog.testing.recordFunction(ctor); - recordedConstructor.prototype = ctor.prototype; - goog.mixin(recordedConstructor, ctor); - return recordedConstructor; -}; - - - -/** - * Struct for a single function call. - * @param {!Function} func The called function. - * @param {!Object} thisContext {@code this} context of called function. - * @param {!Arguments} args Arguments of the called function. - * @param {*} ret Return value of the function or undefined in case of error. - * @param {*} error The error thrown by the function or null if none. - * @constructor - */ -goog.testing.FunctionCall = function(func, thisContext, args, ret, error) { - this.function_ = func; - this.thisContext_ = thisContext; - this.arguments_ = Array.prototype.slice.call(args); - this.returnValue_ = ret; - this.error_ = error; -}; - - -/** - * @return {!Function} The called function. - */ -goog.testing.FunctionCall.prototype.getFunction = function() { - return this.function_; -}; - - -/** - * @return {!Object} {@code this} context of called function. It is the same as - * the created object if the function is a constructor. - */ -goog.testing.FunctionCall.prototype.getThis = function() { - return this.thisContext_; -}; - - -/** - * @return {!Array} Arguments of the called function. - */ -goog.testing.FunctionCall.prototype.getArguments = function() { - return this.arguments_; -}; - - -/** - * Returns the nth argument of the called function. - * @param {number} index 0-based index of the argument. - * @return {*} The argument value or undefined if there is no such argument. - */ -goog.testing.FunctionCall.prototype.getArgument = function(index) { - return this.arguments_[index]; -}; - - -/** - * @return {*} Return value of the function or undefined in case of error. - */ -goog.testing.FunctionCall.prototype.getReturnValue = function() { - return this.returnValue_; -}; - - -/** - * @return {*} The error thrown by the function or null if none. - */ -goog.testing.FunctionCall.prototype.getError = function() { - return this.error_; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/recordfunction_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/recordfunction_test.html.svn-base deleted file mode 100644 index bb78aee..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/recordfunction_test.html.svn-base +++ /dev/null @@ -1,159 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2010 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.recordFunction</title> -<script src="../base.js"></script> -<script> - goog.require('goog.functions'); - goog.require('goog.testing.PropertyReplacer'); - goog.require('goog.testing.jsunit'); - goog.require('goog.testing.recordConstructor'); - goog.require('goog.testing.recordFunction'); -</script> -</head> -<body> -<script> - -var stubs = new goog.testing.PropertyReplacer(); - -function tearDown() { - stubs.reset(); -} - -function testNoCalls() { - var f = goog.testing.recordFunction(goog.functions.identity); - assertEquals('call count', 0, f.getCallCount()); - assertNull('last call', f.getLastCall()); - assertArrayEquals('all calls', [], f.getCalls()); -} - -function testWithoutArguments() { - var f = goog.testing.recordFunction(); - assertUndefined('f(1)', f(1)); - assertEquals('call count', 1, f.getCallCount()); - var lastCall = f.getLastCall(); - assertEquals('original function', goog.nullFunction, lastCall.getFunction()); - assertEquals('this context', window, lastCall.getThis()); - assertArrayEquals('arguments', [1], lastCall.getArguments()); - assertEquals('arguments[0]', 1, lastCall.getArgument(0)); - assertUndefined('arguments[1]', lastCall.getArgument(1)); - assertUndefined('return value', lastCall.getReturnValue()); -} - -function testWithIdentityFunction() { - var f = goog.testing.recordFunction(goog.functions.identity); - var dummyThis = {}; - assertEquals('f(1)', 1, f(1)); - assertEquals('f.call(dummyThis, 2)', 2, f.call(dummyThis, 2)); - - var calls = f.getCalls(); - var firstCall = calls[0]; - var lastCall = f.getLastCall(); - assertEquals('call count', 2, f.getCallCount()); - assertEquals('last call', calls[1], lastCall); - assertEquals('original function', goog.functions.identity, - lastCall.getFunction()); - assertEquals('this context of first call', window, firstCall.getThis()); - assertEquals('this context of last call', dummyThis, lastCall.getThis()); - assertArrayEquals('arguments of the first call', [1], - firstCall.getArguments()); - assertArrayEquals('arguments of the last call', [2], lastCall.getArguments()); - assertEquals('return value of the first call', 1, firstCall.getReturnValue()); - assertEquals('return value of the last call', 2, lastCall.getReturnValue()); - assertNull('error thrown by the first call', firstCall.getError()); - assertNull('error thrown by the last call', lastCall.getError()); -} - -function testWithErrorFunction() { - var f = goog.testing.recordFunction(goog.functions.error('error')); - - var error = assertThrows('f(1) should throw an error', function() { - f(1); - }); - assertEquals('error message', 'error', error.message); - assertEquals('call count', 1, f.getCallCount()); - var lastCall = f.getLastCall(); - assertEquals('this context', window, lastCall.getThis()); - assertArrayEquals('arguments', [1], lastCall.getArguments()); - assertUndefined('return value', lastCall.getReturnValue()); - assertEquals('recorded error message', 'error', lastCall.getError().message); -} - -function testWithClass() { - var ns = {}; - /** @constructor */ - ns.TestClass = function(num) { - this.setX(ns.TestClass.identity(1) + num); - } - ns.TestClass.prototype.setX = function(x) { - this.x = x; - }; - ns.TestClass.identity = function(x) { - return x; - }; - var originalNsTestClass = ns.TestClass; - - stubs.set(ns, 'TestClass', goog.testing.recordConstructor(ns.TestClass)); - stubs.set(ns.TestClass.prototype, 'setX', - goog.testing.recordFunction(ns.TestClass.prototype.setX)); - stubs.set(ns.TestClass, 'identity', - goog.testing.recordFunction(ns.TestClass.identity)); - - var obj = new ns.TestClass(2); - assertEquals('constructor is called once', 1, ns.TestClass.getCallCount()); - var lastConstructorCall = ns.TestClass.getLastCall(); - assertArrayEquals('... with argument 2', [2], - lastConstructorCall.getArguments()); - assertEquals('the created object', obj, lastConstructorCall.getThis()); - assertEquals('type of the created object', originalNsTestClass, - obj.constructor); - - assertEquals('setX is called once', 1, obj.setX.getCallCount()); - assertArrayEquals('... with argument 3', [3], - obj.setX.getLastCall().getArguments()); - assertEquals('The x field is properly set', 3, obj.x); - - assertEquals('identity is called once', 1, - ns.TestClass.identity.getCallCount()); - assertArrayEquals('... with argument 1', [1], - ns.TestClass.identity.getLastCall().getArguments()); -} - -function testPopLastCall() { - var f = goog.testing.recordFunction(); - f(0); - f(1); - - var firstCall = f.getCalls()[0]; - var lastCall = f.getCalls()[1]; - assertEquals('return value of popLastCall', lastCall, f.popLastCall()); - assertArrayEquals('1 call remains', [firstCall], f.getCalls()); - assertEquals('next return value of popLastCall', firstCall, f.popLastCall()); - assertArrayEquals('0 calls remain', [], f.getCalls()); - assertNull('no more calls to pop', f.popLastCall()); -} - -function testReset() { - var f = goog.testing.recordFunction(); - f(0); - f(1); - - assertEquals('Should be two calls.', 2, f.getCallCount()); - - f.reset(); - - assertEquals('Call count should reset.', 0, f.getCallCount()); -} - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/shardingtestcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/shardingtestcase.js.svn-base deleted file mode 100644 index 2798b43..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/shardingtestcase.js.svn-base +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utility for sharding tests. - * - * Usage instructions: - * <ol> - * <li>Instead of writing your large test in foo_test.html, write it in - * foo_test_template.html</li> - * <li>Add a call to {@code goog.testing.ShardingTestCase.shardByFileName()} - * near the top of your test, before any test cases or setup methods.</li> - * <li>Symlink foo_test_template.html into different sharded test files - * named foo_1of4_test.html, foo_2of4_test.html, etc, using `ln -s`.</li> - * <li>Add the symlinks as foo_1of4_test.html. - * In perforce, run the command `g4 add foo_1of4_test.html` followed - * by `g4 reopen -t symlink foo_1of4_test.html` so that perforce treats the file - * as a symlink - * </li> - * </ol> - * - */ - -goog.provide('goog.testing.ShardingTestCase'); - -goog.require('goog.asserts'); -goog.require('goog.testing.TestCase'); - -/** - * A test case that runs tests in per-file shards. - * @param {number} shardIndex Shard index for this page, - * <strong>1-indexed</strong>. - * @param {number} numShards Number of shards to split up test cases into. - * @extends {goog.testing.TestCase} - * @constructor - */ -goog.testing.ShardingTestCase = function(shardIndex, numShards, opt_name) { - goog.base(this, opt_name); - - goog.asserts.assert(shardIndex > 0, 'Shard index should be positive'); - goog.asserts.assert(numShards > 0, 'Number of shards should be positive'); - goog.asserts.assert(shardIndex <= numShards, - 'Shard index out of bounds'); - - /** - * @type {number} - * @private - */ - this.shardIndex_ = shardIndex; - - /** - * @type {number} - * @private - */ - this.numShards_ = numShards; -}; -goog.inherits(goog.testing.ShardingTestCase, goog.testing.TestCase); - - -/** - * Whether we've actually partitioned the tests yet. We may execute twice - * ('Run again without reloading') without failing. - * @type {boolean} - * @private - */ -goog.testing.ShardingTestCase.prototype.sharded_ = false; - - -/** - * Installs a runTests global function that goog.testing.JsUnit will use to - * run tests, which will run a single shard of the tests present on the page. - */ -goog.testing.ShardingTestCase.prototype.runTests = function() { - if (!this.sharded_) { - var numTests = this.getCount(); - goog.asserts.assert(numTests >= this.numShards_, - 'Must have at least as many tests as shards!'); - var shardSize = Math.ceil(numTests / this.numShards_); - var startIndex = (this.shardIndex_ - 1) * shardSize; - var endIndex = startIndex + shardSize; - goog.asserts.assert(this.order == goog.testing.TestCase.Order.SORTED, - 'Only SORTED order is allowed for sharded tests'); - this.setTests(this.getTests().slice(startIndex, endIndex)); - this.sharded_ = true; - } - - // Call original runTests method to execute the tests. - goog.base(this, 'runTests'); -}; - - -/** - * Shards tests based on the test filename. Assumes that the filename is - * formatted like 'foo_1of5_test.html'. - * @param {string=} opt_name A descriptive name for the test case. - */ -goog.testing.ShardingTestCase.shardByFileName = function(opt_name) { - var path = window.location.pathname; - var shardMatch = path.match(/_(\d+)of(\d+)_test\.html/); - goog.asserts.assert(shardMatch, - 'Filename must be of the form "foo_1of5_test.html"'); - var shardIndex = parseInt(shardMatch[1], 10); - var numShards = parseInt(shardMatch[2], 10); - - var testCase = new goog.testing.ShardingTestCase( - shardIndex, numShards, opt_name); - goog.testing.TestCase.initializeTestRunner(testCase); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/shardingtestcase_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/shardingtestcase_test.html.svn-base deleted file mode 100644 index cc79280..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/shardingtestcase_test.html.svn-base +++ /dev/null @@ -1,34 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2011 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.asserts</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.ShardingTestCase'); - goog.require('goog.testing.asserts'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - -goog.testing.TestCase.initializeTestRunner( - new goog.testing.ShardingTestCase(1, 2)); - -function testA() { -} - -function testB() { - fail('testB should not be in this shard'); -} - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/singleton.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/singleton.js.svn-base deleted file mode 100644 index 73187c2..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/singleton.js.svn-base +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview This module simplifies testing code which uses many stateful - * singletons. The {@link goog.testing.singleton.addSingletonGetter} function - * adds a static {@code getInstance} method to the class, which in addition to - * creating and returning a singleton instance, registers it in a global - * repository. This way the effect of all {@code getInstance} calls can be - * simply reset in {@code tearDown} without knowing what singletons were - * instantiated in the tests. - * - * Usage: - * <ol> - * <li>Load {@code base.js}. - * <li>Load {@code goog.testing.singleton}. It overrides - * {@link goog.addSingletonGetter} by - * {@link goog.testing.addSingletonGetter}. - * <li>Load the code to test. - * <li>Call {@link goog.testing.singleton.reset} in the {@code tearDown}. - * </ol> - * - */ - -goog.provide('goog.testing.singleton'); - -goog.require('goog.array'); - - -/** - * List of all singleton classes for which the instance has been created. - * @type {Array.<!Function>} - * @private - */ -goog.testing.singletons_ = []; - - -/** - * Adds a {@code getInstance} static method to the given class which in addition - * to always returning the same instance object, registers the constructor in a - * global array. - * @param {!Function} ctor The constructor for the class to add the static - * method to. - */ -goog.testing.singleton.addSingletonGetter = function(ctor) { - ctor.getInstance = function() { - if (!ctor.instance_) { - ctor.instance_ = new ctor(); - goog.testing.singletons_.push(ctor); - } - return ctor.instance_; - }; -}; - - -/** - * Deletes all singleton instances, so {@code getInstance} will return a new - * instance on next call. - */ -goog.testing.singleton.reset = function() { - goog.array.forEach(goog.testing.singletons_, function(ctor) { - delete ctor.instance_; - }); - goog.array.clear(goog.testing.singletons_); -}; - - -/** - * Overrides {@code goog.addSingletonGetter} in {@code base.js}. - */ -goog.addSingletonGetter = goog.testing.singleton.addSingletonGetter; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/singleton_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/singleton_test.html.svn-base deleted file mode 100644 index 2012ce9..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/singleton_test.html.svn-base +++ /dev/null @@ -1,39 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2009 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.singleton</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.asserts'); - goog.require('goog.testing.jsunit'); - goog.require('goog.testing.singleton'); -</script> -</head> -<body> -<script> - -function testGetInstance() { - function SingletonClass() {} - goog.addSingletonGetter(SingletonClass); - - var s1 = SingletonClass.getInstance(); - var s2 = SingletonClass.getInstance(); - assertEquals('second getInstance call returns the same instance', s1, s2); - - goog.testing.singleton.reset(); - var s3 = SingletonClass.getInstance(); - assertNotEquals('getInstance returns a new instance after reset', s1, s3); -} - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/stacktrace.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/stacktrace.js.svn-base deleted file mode 100644 index 4159135..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/stacktrace.js.svn-base +++ /dev/null @@ -1,470 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Tools for parsing and pretty printing error stack traces. - * - */ - -goog.provide('goog.testing.stacktrace'); -goog.provide('goog.testing.stacktrace.Frame'); - - - -/** - * Class representing one stack frame. - * @param {string} context Context object, empty in case of global functions or - * if the browser doesn't provide this information. - * @param {string} name Function name, empty in case of anonymous functions. - * @param {string} alias Alias of the function if available. For example the - * function name will be 'c' and the alias will be 'b' if the function is - * defined as <code>a.b = function c() {};</code>. - * @param {string} args Arguments of the function in parentheses if available. - * @param {string} path File path or URL including line number and optionally - * column number separated by colons. - * @constructor - */ -goog.testing.stacktrace.Frame = function(context, name, alias, args, path) { - this.context_ = context; - this.name_ = name; - this.alias_ = alias; - this.args_ = args; - this.path_ = path; -}; - - -/** - * @return {string} The function name or empty string if the function is - * anonymous and the object field which it's assigned to is unknown. - */ -goog.testing.stacktrace.Frame.prototype.getName = function() { - return this.name_; -}; - - -/** - * @return {boolean} Whether the stack frame contains an anonymous function. - */ -goog.testing.stacktrace.Frame.prototype.isAnonymous = function() { - return !this.name_ || this.context_ == '[object Object]'; -}; - - -/** - * Brings one frame of the stack trace into a common format across browsers. - * @return {string} Pretty printed stack frame. - */ -goog.testing.stacktrace.Frame.prototype.toCanonicalString = function() { - var htmlEscape = goog.testing.stacktrace.htmlEscape_; - var deobfuscate = goog.testing.stacktrace.maybeDeobfuscateFunctionName_; - - var canonical = [ - this.context_ ? htmlEscape(this.context_) + '.' : '', - this.name_ ? htmlEscape(deobfuscate(this.name_)) : 'anonymous', - htmlEscape(this.args_), - this.alias_ ? ' [as ' + htmlEscape(deobfuscate(this.alias_)) + ']' : '' - ]; - - if (this.path_) { - canonical.push(' at '); - // If Closure Inspector is installed and running, then convert the line - // into a source link for displaying the code in Firebug. - if (goog.testing.stacktrace.isClosureInspectorActive_()) { - var lineNumber = this.path_.match(/\d+$/)[0]; - canonical.push('<a href="" onclick="CLOSURE_INSPECTOR___.showLine(\'', - htmlEscape(this.path_), '\', \'', lineNumber, '\'); return false">', - htmlEscape(this.path_), '</a>'); - } else { - canonical.push(htmlEscape(this.path_)); - } - } - return canonical.join(''); -}; - - -/** - * Maximum number of steps while the call chain is followed. - * @type {number} - * @private - */ -goog.testing.stacktrace.MAX_DEPTH_ = 20; - - -/** - * Maximum length of a string that can be matched with a RegExp on - * Firefox 3x. Exceeding this approximate length will cause string.match - * to exceed Firefox's stack quota. This situation can be encountered - * when goog.globalEval is invoked with a long argument; such as - * when loading a module. - * @type {number} - * @private - */ -goog.testing.stacktrace.MAX_FIREFOX_FRAMESTRING_LENGTH_ = 500000; - - -/** - * RegExp pattern for JavaScript identifiers. We don't support Unicode - * identifiers defined in ECMAScript v3. - * @type {string} - * @private - */ -goog.testing.stacktrace.IDENTIFIER_PATTERN_ = '[a-zA-Z_$][\\w$]*'; - - -/** - * RegExp pattern for function name alias in the Chrome stack trace. - * @type {string} - * @private - */ -goog.testing.stacktrace.CHROME_ALIAS_PATTERN_ = - '(?: \\[as (' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')\\])?'; - - -/** - * RegExp pattern for function names and constructor calls in the Chrome stack - * trace. - * @type {string} - * @private - */ -goog.testing.stacktrace.CHROME_FUNCTION_NAME_PATTERN_ = - '(?:new )?(?:' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + - '|<anonymous>)'; - - -/** - * RegExp pattern for function call in the Chrome stack trace. - * Creates 3 submatches with context object (optional), function name and - * function alias (optional). - * @type {string} - * @private - */ -goog.testing.stacktrace.CHROME_FUNCTION_CALL_PATTERN_ = - ' (?:(.*?)\\.)?(' + goog.testing.stacktrace.CHROME_FUNCTION_NAME_PATTERN_ + - ')' + goog.testing.stacktrace.CHROME_ALIAS_PATTERN_; - - -/** - * RegExp pattern for an URL + position inside the file. - * @type {string} - * @private - */ -goog.testing.stacktrace.URL_PATTERN_ = - '((?:http|https|file)://[^\\s)]+|javascript:.*)'; - - -/** - * RegExp pattern for an URL + line number + column number in Chrome. - * The URL is either in submatch 1 or submatch 2. - * @type {string} - * @private - */ -goog.testing.stacktrace.CHROME_URL_PATTERN_ = ' (?:' + - '\\(unknown source\\)' + '|' + - '\\(native\\)' + '|' + - '\\((?:eval at )?' + goog.testing.stacktrace.URL_PATTERN_ + '\\)' + '|' + - goog.testing.stacktrace.URL_PATTERN_ + ')'; - - -/** - * Regular expression for parsing one stack frame in Chrome. - * @type {!RegExp} - * @private - */ -goog.testing.stacktrace.CHROME_STACK_FRAME_REGEXP_ = new RegExp('^ at' + - '(?:' + goog.testing.stacktrace.CHROME_FUNCTION_CALL_PATTERN_ + ')?' + - goog.testing.stacktrace.CHROME_URL_PATTERN_ + '$'); - - -/** - * RegExp pattern for function call in the Firefox stack trace. - * Creates 2 submatches with function name (optional) and arguments. - * @type {string} - * @private - */ -goog.testing.stacktrace.FIREFOX_FUNCTION_CALL_PATTERN_ = - '(' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')?' + - '(\\(.*\\))?@'; - - -/** - * Regular expression for parsing one stack frame in Firefox. - * @type {!RegExp} - * @private - */ -goog.testing.stacktrace.FIREFOX_STACK_FRAME_REGEXP_ = new RegExp('^' + - goog.testing.stacktrace.FIREFOX_FUNCTION_CALL_PATTERN_ + - '(?::0|' + goog.testing.stacktrace.URL_PATTERN_ + ')$'); - - -/** - * Regular expression for finding the function name in its source. - * @type {!RegExp} - * @private - */ -goog.testing.stacktrace.FUNCTION_SOURCE_REGEXP_ = new RegExp( - '^function (' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')'); - - -/** - * Creates a stack trace by following the call chain. Based on - * {@link goog.debug.getStacktrace}. - * @return {!Array.<!goog.testing.stacktrace.Frame>} Stack frames. - * @private - */ -goog.testing.stacktrace.followCallChain_ = function() { - var frames = []; - var fn = arguments.callee.caller; - var depth = 0; - - while (fn && depth < goog.testing.stacktrace.MAX_DEPTH_) { - var fnString = Function.prototype.toString.call(fn); - var match = fnString.match(goog.testing.stacktrace.FUNCTION_SOURCE_REGEXP_); - var functionName = match ? match[1] : ''; - - var argsBuilder = ['(']; - if (fn.arguments) { - for (var i = 0; i < fn.arguments.length; i++) { - var arg = fn.arguments[i]; - if (i > 0) { - argsBuilder.push(', '); - } - if (goog.isString(arg)) { - argsBuilder.push('"', arg, '"'); - } else { - // Some args are mocks, and we don't want to fail from them not having - // expected a call to toString, so instead insert a static string. - if (arg && arg['$replay']) { - argsBuilder.push('goog.testing.Mock'); - } else { - argsBuilder.push(String(arg)); - } - } - } - } else { - // Opera 10 doesn't know the arguments of native functions. - argsBuilder.push('unknown'); - } - argsBuilder.push(')'); - var args = argsBuilder.join(''); - - frames.push(new goog.testing.stacktrace.Frame('', functionName, '', args, - '')); - - /** @preserveTry */ - try { - fn = fn.caller; - } catch (e) { - break; - } - depth++; - } - - return frames; -}; - - -/** - * Parses one stack frame. - * @param {string} frameStr The stack frame as string. - * @return {goog.testing.stacktrace.Frame} Stack frame object or null if the - * parsing failed. - * @private - */ -goog.testing.stacktrace.parseStackFrame_ = function(frameStr) { - var m = frameStr.match(goog.testing.stacktrace.CHROME_STACK_FRAME_REGEXP_); - if (m) { - return new goog.testing.stacktrace.Frame(m[1] || '', m[2] || '', m[3] || '', - '', m[4] || m[5] || ''); - } - - if (frameStr.length > - goog.testing.stacktrace.MAX_FIREFOX_FRAMESTRING_LENGTH_) { - return goog.testing.stacktrace.parseLongFirefoxFrame_(frameStr); - } - - m = frameStr.match(goog.testing.stacktrace.FIREFOX_STACK_FRAME_REGEXP_); - if (m) { - return new goog.testing.stacktrace.Frame('', m[1] || '', '', m[2] || '', - m[3] || ''); - } - - return null; -}; - - -/** - * Parses a long firefox stack frame. - * @param {string} frameStr The stack frame as string. - * @return {!goog.testing.stacktrace.Frame} Stack frame object. - * @private - */ -goog.testing.stacktrace.parseLongFirefoxFrame_ = function(frameStr) { - var firstParen = frameStr.indexOf('('); - var lastAmpersand = frameStr.lastIndexOf('@'); - var lastColon = frameStr.lastIndexOf(':'); - var functionName = ''; - if ((firstParen >= 0) && (firstParen < lastAmpersand)) { - functionName = frameStr.substring(0, firstParen); - } - var loc = ''; - if ((lastAmpersand >= 0) && (lastAmpersand + 1 < lastColon)) { - loc = frameStr.substring(lastAmpersand + 1); - } - var args = ''; - if ((firstParen >= 0 && lastAmpersand > 0) && - (firstParen < lastAmpersand)) { - args = frameStr.substring(firstParen, lastAmpersand); - } - return new goog.testing.stacktrace.Frame('', functionName, '', args, loc); -}; - - -/** - * Function to deobfuscate function names. - * @type {function(string): string} - * @private - */ -goog.testing.stacktrace.deobfuscateFunctionName_; - - -/** - * Sets function to deobfuscate function names. - * @param {function(string): string} fn function to deobfuscate function names. - */ -goog.testing.stacktrace.setDeobfuscateFunctionName = function(fn) { - goog.testing.stacktrace.deobfuscateFunctionName_ = fn; -}; - - -/** - * Deobfuscates a compiled function name with the function passed to - * {@link #setDeobfuscateFunctionName}. Returns the original function name if - * the deobfuscator hasn't been set. - * @param {string} name The function name to deobfuscate. - * @return {string} The deobfuscated function name. - * @private - */ -goog.testing.stacktrace.maybeDeobfuscateFunctionName_ = function(name) { - return goog.testing.stacktrace.deobfuscateFunctionName_ ? - goog.testing.stacktrace.deobfuscateFunctionName_(name) : name; -}; - - -/** - * @return {boolean} Whether the Closure Inspector is active. - * @private - */ -goog.testing.stacktrace.isClosureInspectorActive_ = function() { - return Boolean(goog.global['CLOSURE_INSPECTOR___'] && - goog.global['CLOSURE_INSPECTOR___']['supportsJSUnit']); -}; - - -/** - * Escapes the special character in HTML. - * @param {string} text Plain text. - * @return {string} Escaped text. - * @private - */ -goog.testing.stacktrace.htmlEscape_ = function(text) { - return text.replace(/&/g, '&'). - replace(/</g, '<'). - replace(/>/g, '>'). - replace(/"/g, '"'); -}; - - -/** - * Converts the stack frames into canonical format. Chops the beginning and the - * end of it which come from the testing environment, not from the test itself. - * @param {!Array.<goog.testing.stacktrace.Frame>} frames The frames. - * @return {string} Canonical, pretty printed stack trace. - * @private - */ -goog.testing.stacktrace.framesToString_ = function(frames) { - // Removes the anonymous calls from the end of the stack trace (they come - // from testrunner.js, testcase.js and asserts.js), so the stack trace will - // end with the test... method. - var lastIndex = frames.length - 1; - while (frames[lastIndex] && frames[lastIndex].isAnonymous()) { - lastIndex--; - } - - // Removes the beginning of the stack trace until the call of the private - // _assert function (inclusive), so the stack trace will begin with a public - // asserter. Does nothing if _assert is not present in the stack trace. - var privateAssertIndex = -1; - for (var i = 0; i < frames.length; i++) { - if (frames[i] && frames[i].getName() == '_assert') { - privateAssertIndex = i; - break; - } - } - - var canonical = []; - for (var i = privateAssertIndex + 1; i <= lastIndex; i++) { - canonical.push('> '); - if (frames[i]) { - canonical.push(frames[i].toCanonicalString()); - } else { - canonical.push('(unknown)'); - } - canonical.push('\n'); - } - return canonical.join(''); -}; - - -/** - * Parses the browser's native stack trace. - * @param {string} stack Stack trace. - * @return {!Array.<goog.testing.stacktrace.Frame>} Stack frames. The - * unrecognized frames will be nulled out. - * @private - */ -goog.testing.stacktrace.parse_ = function(stack) { - var lines = stack.replace(/\s*$/, '').split('\n'); - var frames = []; - for (var i = 0; i < lines.length; i++) { - frames.push(goog.testing.stacktrace.parseStackFrame_(lines[i])); - } - return frames; -}; - - -/** - * Brings the stack trace into a common format across browsers. - * @param {string} stack Browser-specific stack trace. - * @return {string} Same stack trace in common format. - */ -goog.testing.stacktrace.canonicalize = function(stack) { - var frames = goog.testing.stacktrace.parse_(stack); - return goog.testing.stacktrace.framesToString_(frames); -}; - - -/** - * Gets the native stack trace if available otherwise follows the call chain. - * @return {string} The stack trace in canonical format. - */ -goog.testing.stacktrace.get = function() { - var stack = new Error().stack; - var frames = stack ? goog.testing.stacktrace.parse_(stack) : - goog.testing.stacktrace.followCallChain_(); - return goog.testing.stacktrace.framesToString_(frames); -}; - - -goog.exportSymbol('setDeobfuscateFunctionName', - goog.testing.stacktrace.setDeobfuscateFunctionName); diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/stacktrace_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/stacktrace_test.html.svn-base deleted file mode 100644 index 28171c1..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/stacktrace_test.html.svn-base +++ /dev/null @@ -1,229 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2009 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.stacktrace</title> -<script src="../base.js"></script> -<script> - goog.require('goog.string'); - goog.require('goog.testing.ExpectedFailures'); - goog.require('goog.testing.PropertyReplacer'); - goog.require('goog.testing.StrictMock'); - goog.require('goog.testing.asserts'); - goog.require('goog.testing.jsunit'); - goog.require('goog.testing.stacktrace'); - goog.require('goog.userAgent'); -</script> -</head> -<body> -<script> - -var stubs = new goog.testing.PropertyReplacer(); -var expectedFailures = new goog.testing.ExpectedFailures(); - -function setUp() { - stubs.set(goog.testing.stacktrace, 'isClosureInspectorActive_', function() { - return false; - }); -} - -function tearDown() { - stubs.reset(); - expectedFailures.handleTearDown(); -} - -function testParseStackFrameInChrome() { - var frameString = ' at Error (unknown source)'; - var frame = goog.testing.stacktrace.parseStackFrame_(frameString); - var expected = new goog.testing.stacktrace.Frame('', 'Error', '', '', ''); - assertObjectEquals('exception name only', expected, frame); - - frameString = ' at Object.assert (file:///.../asserts.js:29:10)'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('Object', 'assert', '', '', - 'file:///.../asserts.js:29:10') - assertObjectEquals('context object + function name + url', expected, frame); - - frameString = ' at http://www.example.com/jsunit.js:117:13'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('', '', '', '', - 'http://www.example.com/jsunit.js:117:13'); - assertObjectEquals('url only', expected, frame); - - frameString = ' at [object Object].exec [as execute] (file:///foo)'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('[object Object]', 'exec', - 'execute', '', 'file:///foo'); - assertObjectEquals('function alias', expected, frame); - - frameString = ' at new Class (file:///foo)'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('', 'new Class', '', '', - 'file:///foo'); - assertObjectEquals('constructor call', expected, frame); - - frameString = ' at new <anonymous> (file:///foo)'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('', 'new <anonymous>', '', '', - 'file:///foo'); - assertObjectEquals('anonymous constructor call', expected, frame); - - frameString = ' at Array.forEach (native)'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('Array', 'forEach', '', '', ''); - assertObjectEquals('native function call', expected, frame); - - frameString = ' at foo (eval at file://bar)'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('', 'foo', '', '', 'file://bar'); - assertObjectEquals('eval', expected, frame); -} - -// All test strings are parsed with the conventional and long -// frame algorithms. -function testParseStackFrameInFirefox() { - var frameString = 'Error("Assertion failed")@:0'; - var frame = goog.testing.stacktrace.parseStackFrame_(frameString); - var expected = new goog.testing.stacktrace.Frame('', 'Error', '', - '("Assertion failed")', ''); - assertObjectEquals('function name + arguments', expected, frame); - - frame = goog.testing.stacktrace.parseLongFirefoxFrame_(frameString); - assertObjectEquals('function name + arguments', expected, frame); - - frameString = '()@file:///foo:42'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('', '', '', '()', - 'file:///foo:42'); - assertObjectEquals('anonymous function', expected, frame); - - frame = goog.testing.stacktrace.parseLongFirefoxFrame_(frameString); - assertObjectEquals('anonymous function', expected, frame); - - frameString = '@javascript:alert(0)'; - frame = goog.testing.stacktrace.parseStackFrame_(frameString); - expected = new goog.testing.stacktrace.Frame('', '', '', '', - 'javascript:alert(0)'); - assertObjectEquals('anonymous function', expected, frame); - - frame = goog.testing.stacktrace.parseLongFirefoxFrame_(frameString); - assertObjectEquals('anonymous function', expected, frame); -} - -function testCanonicalizeFrame() { - var frame = new goog.testing.stacktrace.Frame('<window>', 'foo', 'bar', - '("<a>\'&")', 'http://x?a=1&b=2:1'); - assertEquals('canonical stack frame, everything is escaped', - '<window>.foo("<a>\'&amp;") ' + - '[as bar] at http://x?a=1&b=2:1', frame.toCanonicalString()); -} - -function testCanonicalizeFrameWithClosureInspector() { - stubs.set(goog.testing.stacktrace, 'isClosureInspectorActive_', function() { - return true; - }); - - var frame = new goog.testing.stacktrace.Frame('', 'foo', '', '()', - 'http://x?a=1&b=2:1'); - assertEquals('canonical stack frame with closure inspector link', - 'foo() at <a href="" onclick="CLOSURE_INSPECTOR___.showLine(' + - '\'http://x?a=1&b=2:1\', \'1\'); return false">' + - 'http://x?a=1&b=2:1<' + '/a>', - frame.toCanonicalString()); -} - -function testDeobfuscateFunctionName() { - goog.testing.stacktrace.setDeobfuscateFunctionName(function(name) { - return name.replace(/\$/g, '.'); - }); - - var frame = new goog.testing.stacktrace.Frame('', 'a$b$c', 'd$e', '', ''); - assertEquals('deobfuscated function name', 'a.b.c [as d.e]', - frame.toCanonicalString()); -} - -function testFramesToString() { - var normalFrame = new goog.testing.stacktrace.Frame('', 'foo', '', '', ''); - var anonFrame = new goog.testing.stacktrace.Frame('', '', '', '', ''); - var frames = [normalFrame, anonFrame, null, anonFrame]; - var stack = goog.testing.stacktrace.framesToString_(frames); - assertEquals('framesToString', '> foo\n> anonymous\n> (unknown)\n', stack); -} - -function testFollowCallChain() { - var func = function(var_args) { - return goog.testing.stacktrace.followCallChain_(); - }; - - // Created a fake type with a toString method. - function LocalType() {}; - LocalType.prototype.toString = function() { - return 'sg'; - }; - - // Create a mock with no expectations. - var mock = new goog.testing.StrictMock(LocalType); - - mock.$replay(); - - var frames = func(undefined, null, false, 0, '', {}, goog.nullFunction, - mock, new LocalType); - - // Opera before version 10 doesn't support the caller attribute. In that - // browser followCallChain_() returns empty stack trace. - expectedFailures.expectFailureFor(goog.userAgent.OPERA && - !goog.userAgent.isVersion('10')); - try { - assertTrue('The stack trace consists of >=2 frames', frames.length >= 2) - } catch (e) { - expectedFailures.handleException(e); - } - - if (frames.length >= 2) { - assertEquals('innermost function is anonymous', '', frames[0].getName()); - // There are white space differences how browsers convert functions to - // strings. - var expected = '(undefined,null,false,0,"",[objectObject],function(){},' + - 'goog.testing.Mock,sg)'; - assertEquals('arguments of the innermost function (ignoring whitespaces)', - expected, frames[0].args_.replace(/\s/g, '')); - assertEquals('test function name', 'testFollowCallChain', - frames[1].getName()); - } - - mock.$verify(); -} - -// Create a stack trace string with one modest record and one long record, -// Verify that all frames are parsed. The length of the long arg is set -// to blow Firefox 3x's stack if put through a RegExp. -function testParsingLongStackTrace() { - var longArg = goog.string.buildString( - '(', goog.string.repeat('x', 1000000), ')'); - var stackTrace = goog.string.buildString( - 'shortFrame()@:0\n', - 'longFrame', - longArg, - '@http://google.com/somescript:0\n'); - var frames = goog.testing.stacktrace.parse_(stackTrace); - assertEquals('number of returned frames', 2, frames.length); - var expected = new goog.testing.stacktrace.Frame( - '', 'shortFrame', '', '()', ''); - assertObjectEquals('short frame', expected, frames[0]); - - expected = new goog.testing.stacktrace.Frame( - '', 'longFrame', '', longArg, 'http://google.com/somescript:0'); - assertObjectEquals('exception name only', expected, frames[1]); -} - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/strictmock.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/strictmock.js.svn-base deleted file mode 100644 index 69914f8..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/strictmock.js.svn-base +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview This file defines a strict mock implementation. - */ - -goog.provide('goog.testing.StrictMock'); - -goog.require('goog.array'); -goog.require('goog.testing.Mock'); - - - -/** - * This is a mock that verifies that methods are called in the order that they - * are specified during the recording phase. Since it verifies order, it - * follows 'fail fast' semantics. If it detects a deviation from the - * expectations, it will throw an exception and not wait for verify to be - * called. - * @param {Object} objectToMock The object to mock. - * @param {boolean=} opt_mockStaticMethods An optional argument denoting that - * a mock should be constructed from the static functions of a class. - * @param {boolean=} opt_createProxy An optional argument denoting that - * a proxy for the target mock should be created. - * @constructor - * @extends {goog.testing.Mock} - */ -goog.testing.StrictMock = function(objectToMock, opt_mockStaticMethods, - opt_createProxy) { - goog.testing.Mock.call(this, objectToMock, opt_mockStaticMethods, - opt_createProxy); - - /** - * An array of MockExpectations. - * @type {Array.<goog.testing.MockExpectation>} - * @private - */ - this.$expectations_ = []; -}; -goog.inherits(goog.testing.StrictMock, goog.testing.Mock); - - -/** @override */ -goog.testing.StrictMock.prototype.$recordExpectation = function() { - this.$expectations_.push(this.$pendingExpectation); -}; - - -/** @override */ -goog.testing.StrictMock.prototype.$recordCall = function(name, args) { - if (this.$expectations_.length == 0) { - this.$throwCallException(name, args); - } - - // If the current expectation has a different name, make sure it was called - // enough and then discard it. We're through with it. - var currentExpectation = this.$expectations_[0]; - while (!this.$verifyCall(currentExpectation, name, args)) { - - // This might be an item which has passed its min, and we can now - // look past it, or it might be below its min and generate an error. - if (currentExpectation.actualCalls < currentExpectation.minCalls) { - this.$throwCallException(name, args, currentExpectation); - } - - this.$expectations_.shift(); - if (this.$expectations_.length < 1) { - // Nothing left, but this may be a failed attempt to call the previous - // item on the list, which may have been between its min and max. - this.$throwCallException(name, args, currentExpectation); - } - currentExpectation = this.$expectations_[0]; - } - - if (currentExpectation.maxCalls == 0) { - this.$throwCallException(name, args); - } - - currentExpectation.actualCalls++; - // If we hit the max number of calls for this expectation, we're finished - // with it. - if (currentExpectation.actualCalls == currentExpectation.maxCalls) { - this.$expectations_.shift(); - } - - return this.$do(currentExpectation, args); -}; - - -/** @override */ -goog.testing.StrictMock.prototype.$reset = function() { - goog.testing.StrictMock.superClass_.$reset.call(this); - - goog.array.clear(this.$expectations_); -}; - - -/** @override */ -goog.testing.StrictMock.prototype.$verify = function() { - goog.testing.StrictMock.superClass_.$verify.call(this); - - while (this.$expectations_.length > 0) { - var expectation = this.$expectations_[0]; - if (expectation.actualCalls < expectation.minCalls) { - this.$throwException('Missing a call to ' + expectation.name + - '\nExpected: ' + expectation.minCalls + ' but was: ' + - expectation.actualCalls); - - } else { - // Don't need to check max, that's handled when the call is made - this.$expectations_.shift(); - } - } -}; - - diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/strictmock_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/strictmock_test.html.svn-base deleted file mode 100644 index c868dd4..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/strictmock_test.html.svn-base +++ /dev/null @@ -1,412 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.testing.StrictMock</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.StrictMock'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<script> - - // The object that we will be mocking - var RealObject = function() { - }; - - RealObject.prototype.a = function() { - fail('real object should never be called'); - }; - - RealObject.prototype.b = function() { - fail('real object should never be called'); - }; - - RealObject.prototype.c = function() { - fail('real object should never be called'); - }; - - var mock; - - function setUp() { - var obj = new RealObject(); - mock = new goog.testing.StrictMock(obj); - } - - - function testMockFunction() { - var mock = new goog.testing.StrictMock(RealObject); - mock.a(); - mock.b(); - mock.c(); - mock.$replay(); - mock.a(); - mock.b(); - mock.c(); - mock.$verify(); - - mock.$reset(); - - assertThrows(function() {mock.x()}); - } - - - function testSimpleExpectations() { - mock.a(); - mock.$replay(); - mock.a(); - mock.$verify(); - - mock.$reset(); - - mock.a(); - mock.b(); - mock.a(); - mock.a(); - mock.$replay(); - mock.a(); - mock.b(); - mock.a(); - mock.a(); - mock.$verify(); - } - - - function testFailToSetExpectation() { - mock.$replay(); - assertThrows(goog.bind(mock.a, mock)); - - mock.$reset(); - - mock.$replay(); - assertThrows(goog.bind(mock.b, mock)); - } - - - function testUnexpectedCall() { - mock.a(); - mock.$replay(); - mock.a(); - assertThrows(goog.bind(mock.a, mock)); - - mock.$reset(); - - mock.a(); - mock.$replay(); - assertThrows(goog.bind(mock.b, mock)); - } - - - function testNotEnoughCalls() { - mock.a(); - mock.$replay(); - assertThrows(goog.bind(mock.$verify, mock)); - - mock.$reset(); - - mock.a(); - mock.b(); - mock.$replay(); - mock.a(); - assertThrows(goog.bind(mock.$verify, mock)); - } - - - function testOutOfOrderCalls() { - mock.a(); - mock.b(); - mock.$replay(); - assertThrows(goog.bind(mock.b, mock)); - } - - - function testVerify() { - mock.a(); - mock.$replay(); - mock.a(); - mock.$verify(); - - mock.$reset(); - - mock.a(); - mock.$replay(); - assertThrows(goog.bind(mock.$verify, mock)); - } - - - function testArgumentMatching() { - mock.a('foo'); - mock.b('bar'); - mock.$replay(); - mock.a('foo'); - assertThrows(function() {mock.b('foo')}); - - mock.$reset(); - mock.a('foo'); - mock.a('bar'); - mock.$replay(); - mock.a('foo'); - mock.a('bar'); - mock.$verify(); - - mock.$reset(); - mock.a('foo'); - mock.a('bar'); - mock.$replay(); - assertThrows(function() {mock.a('bar')}); - } - - - function testReturnValue() { - mock.a().$returns(5); - mock.$replay(); - - assertEquals('Mock should return the right value', 5, mock.a()); - - mock.$verify(); - } - - - function testAtMostOnce() { - // Zero times SUCCESS. - mock.a().$atMostOnce(); - mock.$replay(); - mock.$verify(); - - mock.$reset(); - - // One time SUCCESS. - mock.a().$atMostOnce(); - mock.$replay(); - mock.a(); - mock.$verify(); - - mock.$reset(); - - // Many times FAIL. - mock.a().$atMostOnce(); - mock.$replay(); - mock.a(); - assertThrows(goog.bind(mock.a, mock)); - - mock.$reset(); - - // atMostOnce only lasts until a new method is called. - mock.a().$atMostOnce(); - mock.b(); - mock.a(); - mock.$replay(); - mock.b(); - assertThrows(goog.bind(mock.$verify, mock)); - } - - - function testAtLeastOnce() { - // atLeastOnce does not mean zero times - mock.a().$atLeastOnce(); - mock.$replay(); - assertThrows(goog.bind(mock.$verify, mock)); - - mock.$reset(); - - // atLeastOnce does mean three times - mock.a().$atLeastOnce(); - mock.$replay(); - mock.a(); - mock.a(); - mock.a(); - mock.$verify(); - - mock.$reset(); - - // atLeastOnce only lasts until a new method is called - mock.a().$atLeastOnce(); - mock.b(); - mock.a(); - mock.$replay(); - mock.a(); - mock.a(); - mock.b(); - mock.a(); - assertThrows(goog.bind(mock.a, mock)); - } - - - function testAtLeastOnceWithArgs() { - mock.a('asdf').$atLeastOnce(); - mock.a('qwert'); - mock.$replay(); - mock.a('asdf'); - mock.a('asdf'); - mock.a('qwert'); - mock.$verify(); - - mock.$reset(); - - mock.a('asdf').$atLeastOnce(); - mock.a('qwert'); - mock.$replay(); - mock.a('asdf'); - mock.a('asdf'); - assertThrows(function() {mock.a('zxcv')}); - assertThrows(goog.bind(mock.$verify, mock)); - } - - - function testAnyTimes() { - mock.a().$anyTimes(); - mock.$replay(); - mock.$verify(); - - mock.$reset(); - - mock.a().$anyTimes(); - mock.$replay(); - mock.a(); - mock.a(); - mock.a(); - mock.a(); - mock.a(); - mock.$verify(); - } - - - function testAnyTimesWithArguments() { - mock.a('foo').$anyTimes(); - mock.$replay(); - mock.$verify(); - - mock.$reset(); - - mock.a('foo').$anyTimes(); - mock.a('bar').$anyTimes(); - mock.$replay(); - mock.a('foo'); - mock.a('foo'); - mock.a('foo'); - mock.a('bar'); - mock.a('bar'); - mock.$verify(); - } - - - function testZeroTimes() { - mock.a().$times(0); - mock.$replay(); - mock.$verify(); - - mock.$reset(); - - mock.a().$times(0); - mock.$replay(); - assertThrows(function() {mock.a()}); - } - - - function testZeroTimesWithArguments() { - mock.a('foo').$times(0); - mock.$replay(); - mock.$verify(); - - mock.$reset(); - - mock.a('foo').$times(0); - mock.$replay(); - assertThrows(function() {mock.a('foo')}); - } - - - function testTooManyCalls() { - mock.a().$times(2); - mock.$replay(); - mock.a(); - mock.a(); - assertThrows(function() {mock.a()}); - } - - - function testTooManyCallsWithArguments() { - mock.a('foo').$times(2); - mock.$replay(); - mock.a('foo'); - mock.a('foo'); - assertThrows(function() {mock.a('foo')}); - } - - - function testMultipleSkippedAnyTimes() { - mock.a().$anyTimes(); - mock.b().$anyTimes(); - mock.c().$anyTimes(); - mock.$replay(); - mock.c(); - mock.$verify(); - } - - - function testMultipleSkippedAnyTimesWithArguments() { - mock.a('foo').$anyTimes(); - mock.a('bar').$anyTimes(); - mock.a('baz').$anyTimes(); - mock.$replay(); - mock.a('baz'); - mock.$verify(); - } - - - function testVerifyThrows() { - mock.a(1); - mock.$replay(); - mock.a(1); - try { - mock.a(2); - fail('bad mock, should fail'); - } catch (ex) { - // this could be an event handler, for example - } - assertThrows(goog.bind(mock.$verify, mock)); - } - - - function testThrows() { - mock.a().$throws('exception!'); - mock.$replay(); - assertThrows(goog.bind(mock.a, mock)); - mock.$verify(); - } - - - function testDoes() { - mock.a(1, 2).$does(function(a, b) {return a + b;}); - mock.$replay(); - assertEquals('Mock should call the function', 3, mock.a(1, 2)); - mock.$verify(); - } - - function testErrorMessageForBadArgs() { - mock.a(); - mock.$anyTimes(); - - mock.$replay(); - - var message; - try { - mock.a('a'); - } catch (e) { - message = e.message; - } - - assertTrue('No exception thrown on verify', goog.isDef(message)); - assertContains('Bad arguments to a()', message); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testcase.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testcase.js.svn-base deleted file mode 100644 index 4d4186c..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testcase.js.svn-base +++ /dev/null @@ -1,1106 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview A class representing a set of test functions to be run. - * - * Testing code should not have dependencies outside of goog.testing so as to - * reduce the chance of masking missing dependencies. - * - * This file does not compile correctly with --collapse_properties. Use - * --property_renaming=ALL_UNQUOTED instead. - * - */ - -goog.provide('goog.testing.TestCase'); -goog.provide('goog.testing.TestCase.Error'); -goog.provide('goog.testing.TestCase.Order'); -goog.provide('goog.testing.TestCase.Result'); -goog.provide('goog.testing.TestCase.Test'); - -goog.require('goog.testing.asserts'); -goog.require('goog.testing.stacktrace'); - - - -/** - * A class representing a JsUnit test case. A TestCase is made up of a number - * of test functions which can be run. Individual test cases can override the - * following functions to set up their test environment: - * - runTests - completely override the test's runner - * - setUpPage - called before any of the test functions are run - * - tearDownPage - called after all tests are finished - * - setUp - called before each of the test functions - * - tearDown - called after each of the test functions - * - shouldRunTests - called before a test run, all tests are skipped if it - * returns false. Can be used to disable tests on browsers - * where they aren't expected to pass. - * - * Use {@link #autoDiscoverTests} - * - * @param {string=} opt_name The name of the test case, defaults to - * 'Untitled Test Case'. - * @constructor - */ -goog.testing.TestCase = function(opt_name) { - /** - * A name for the test case. - * @type {string} - * @private - */ - this.name_ = opt_name || 'Untitled Test Case'; - - /** - * Array of test functions that can be executed. - * @type {Array.<goog.testing.TestCase.Test>} - * @private - */ - this.tests_ = []; - - /** - * Set of test names and/or indices to execute, or null if all tests should - * be executed. - * - * Indices are included to allow automation tools to run a subset of the - * tests without knowing the exact contents of the test file. - * - * Indices should only be used with SORTED ordering. - * - * Example valid values: - * <ul> - * <li>[testName] - * <li>[testName1, testName2] - * <li>[2] - will run the 3rd test in the order specified - * <li>[1,3,5] - * <li>[testName1, testName2, 3, 5] - will work - * <ul> - * @type {Object} - * @private - */ - this.testsToRun_ = null; - - var search = window.location.search; - - // Parse the 'runTests' query parameter into a set of test names and/or - // test indices. - var runTestsMatch = search.match(/(?:\?|&)runTests=([^?&]+)/i); - if (runTestsMatch) { - this.testsToRun_ = {}; - var arr = runTestsMatch[1].split(','); - for (var i = 0, len = arr.length; i < len; i++) { - this.testsToRun_[arr[i]] = 1; - } - } - - // Checks the URL for a valid order param. - var orderMatch = search.match(/(?:\?|&)order=(natural|random|sorted)/i); - if (orderMatch) { - this.order = orderMatch[1]; - } - - /** - * Object used to encapsulate the test results. - * @type {goog.testing.TestCase.Result} - * @protected - * @suppress {underscore} - */ - this.result_ = new goog.testing.TestCase.Result(this); - - // This silences a compiler warning from the legacy property check, which - // is deprecated. It idly writes to testRunner properties that are used - // in this file. - var testRunnerMethods = {isFinished: true, hasErrors: true}; -}; - - -/** - * The order to run the auto-discovered tests. - * @enum {string} - */ -goog.testing.TestCase.Order = { - /** - * This is browser dependent and known to be different in FF and Safari - * compared to others. - */ - NATURAL: 'natural', - - /** Random order. */ - RANDOM: 'random', - - /** Sorted based on the name. */ - SORTED: 'sorted' -}; - - -/** - * The maximum amount of time that the test can run before we force it to be - * async. This prevents the test runner from blocking the browser and - * potentially hurting the Selenium test harness. - * @type {number} - */ -goog.testing.TestCase.MAX_RUN_TIME = 200; - - -/** - * The order to run the auto-discovered tests in. - * @type {string} - */ -goog.testing.TestCase.prototype.order = goog.testing.TestCase.Order.SORTED; - - -/** - * Save a reference to window.timeout, so any code that overrides the default - * behavior (e.g. MockClock) doesn't affect our runner. - * @type {function((Function|string), number, *=): number} - * @private - */ -goog.testing.TestCase.protectedTimeout_ = window.setTimeout; - - -/** - * Saved string referencing window.setTimeout's string serialization. IE - * sometimes fails to uphold equality for setTimeout, but the string version - * stays the same. - * @type {string} - * @private - */ -goog.testing.TestCase.setTimeoutAsString_ = String(window.setTimeout); - - -/** - * TODO(user) replace this with prototype.currentTest. - * Name of the current test that is running, or null if none is running. - * @type {?string} - */ -goog.testing.TestCase.currentTestName = null; - - -/** - * Avoid a dependency on goog.userAgent and keep our own reference of whether - * the browser is IE. - * @type {boolean} - */ -goog.testing.TestCase.IS_IE = typeof opera == 'undefined' && !!navigator && - navigator.userAgent.indexOf('MSIE') != -1; - - -/** - * Whether the test case has ever tried to execute. - * @type {boolean} - */ -goog.testing.TestCase.prototype.started = false; - - -/** - * Whether the test case is running. - * @type {boolean} - */ -goog.testing.TestCase.prototype.running = false; - - -/** - * Timestamp for when the test was started. - * @type {number} - * @private - */ -goog.testing.TestCase.prototype.startTime_ = 0; - - -/** - * Time since the last batch of tests was started, if batchTime exceeds - * {@link #MAX_RUN_TIME} a timeout will be used to stop the tests blocking the - * browser and a new batch will be started. - * @type {number} - * @private - */ -goog.testing.TestCase.prototype.batchTime_ = 0; - - -/** - * Pointer to the current test. - * @type {number} - * @private - */ -goog.testing.TestCase.prototype.currentTestPointer_ = 0; - - -/** - * Optional callback that will be executed when the test has finalized. - * @type {Function} - * @private - */ -goog.testing.TestCase.prototype.onCompleteCallback_ = null; - - -/** - * The test runner that is running this case. - * @type {goog.testing.TestRunner?} - * @private - */ -goog.testing.TestCase.prototype.testRunner_ = null; - - -/** - * Adds a new test to the test case. - * @param {goog.testing.TestCase.Test} test The test to add. - */ -goog.testing.TestCase.prototype.add = function(test) { - this.tests_.push(test); -}; - - -/** - * Sets the tests. - * @param {Array.<goog.testing.TestCase.Test>} tests A new test array. - * @protected - */ -goog.testing.TestCase.prototype.setTests = function(tests) { - this.tests_ = tests; -}; - - -/** - * Gets the tests. - * @return {Array.<goog.testing.TestCase.Test>} The test array. - * @protected - */ -goog.testing.TestCase.prototype.getTests = function() { - return this.tests_; -}; - - -/** - * Returns the number of tests contained in the test case. - * @return {number} The number of tests. - */ -goog.testing.TestCase.prototype.getCount = function() { - return this.tests_.length; -}; - - -/** - * Returns the current test and increments the pointer. - * @return {goog.testing.TestCase.Test?} The current test case. - */ -goog.testing.TestCase.prototype.next = function() { - var test; - while ((test = this.tests_[this.currentTestPointer_++])) { - if (!this.testsToRun_ || this.testsToRun_[test.name] || - this.testsToRun_[this.currentTestPointer_ - 1]) { - return test; - } - } - return null; -}; - - -/** - * Resets the test case pointer, so that next returns the first test. - */ -goog.testing.TestCase.prototype.reset = function() { - this.currentTestPointer_ = 0; - this.result_ = new goog.testing.TestCase.Result(this); -}; - - -/** - * Sets the callback function that should be executed when the tests have - * completed. - * @param {Function} fn The callback function. - */ -goog.testing.TestCase.prototype.setCompletedCallback = function(fn) { - this.onCompleteCallback_ = fn; -}; - - -/** - * Sets the test runner that is running this test case. - * @param {goog.testing.TestRunner} tr The test runner. - */ -goog.testing.TestCase.prototype.setTestRunner = function(tr) { - this.testRunner_ = tr; -}; - - -/** - * Can be overridden in test classes to indicate whether the tests in a case - * should be run in that particular situation. For example, this could be used - * to stop tests running in a particular browser, where browser support for - * the class under test was absent. - * @return {boolean} Whether any of the tests in the case should be run. - */ -goog.testing.TestCase.prototype.shouldRunTests = function() { - return true; -}; - - -/** - * Executes each of the tests. - */ -goog.testing.TestCase.prototype.execute = function() { - this.started = true; - this.reset(); - this.startTime_ = this.now_(); - this.running = true; - this.result_.totalCount = this.getCount(); - - if (!this.shouldRunTests()) { - this.log('shouldRunTests() returned false, skipping these tests.'); - this.result_.testSuppressed = true; - this.finalize(); - return; - } - - this.log('Starting tests: ' + this.name_); - this.cycleTests(); -}; - - -/** - * Finalizes the test case, called when the tests have finished executing. - */ -goog.testing.TestCase.prototype.finalize = function() { - this.saveMessage('Done'); - - this.tearDownPage(); - - var restoredSetTimeout = - goog.testing.TestCase.protectedTimeout_ == window.setTimeout; - if (!restoredSetTimeout && goog.testing.TestCase.IS_IE && - String(window.setTimeout) == goog.testing.TestCase.setTimeoutAsString_) { - // In strange cases, IE's value of setTimeout *appears* to change, but - // the string representation stays stable. - restoredSetTimeout = true; - } - - if (!restoredSetTimeout) { - var message = 'ERROR: Test did not restore setTimeout'; - this.saveMessage(message); - var err = new goog.testing.TestCase.Error(this.name_, message); - this.result_.errors.push(err); - } - window.setTimeout = goog.testing.TestCase.protectedTimeout_; - this.endTime_ = this.now_(); - this.running = false; - this.result_.runTime = this.endTime_ - this.startTime_; - this.result_.numFilesLoaded = this.countNumFilesLoaded_(); - - this.log(this.result_.getSummary()); - - if (this.result_.isSuccess()) { - this.log('Tests complete'); - } else { - this.log('Tests Failed'); - } - if (this.onCompleteCallback_) { - var fn = this.onCompleteCallback_; - // Execute's the completed callback in the context of the global object. - fn(); - this.onCompleteCallback_ = null; - } -}; - - -/** - * Saves a message to the result set. - * @param {string} message The message to save. - */ -goog.testing.TestCase.prototype.saveMessage = function(message) { - this.result_.messages.push(this.getTimeStamp_() + ' ' + message); -}; - - -/** - * @return {boolean} Whether the test case is running inside the multi test - * runner. - */ -goog.testing.TestCase.prototype.isInsideMultiTestRunner = function() { - var top = goog.global['top']; - return top && typeof top['_allTests'] != 'undefined'; -}; - - -/** - * Logs an object to the console, if available. - * @param {*} val The value to log. Will be ToString'd. - */ -goog.testing.TestCase.prototype.log = function(val) { - if (!this.isInsideMultiTestRunner() && window.console) { - if (typeof val == 'string') { - val = this.getTimeStamp_() + ' : ' + val; - } - if (val instanceof Error && val.stack) { - // Chrome does console.log asynchronously in a different process - // (http://code.google.com/p/chromium/issues/detail?id=50316). - // This is an acute problem for Errors, which almost never survive. - // Grab references to the immutable strings so they survive. - window.console.log(val, val.message, val.stack); - // TODO(gboyer): Consider for Chrome cloning any object if we can ensure - // there are no circular references. - } else { - window.console.log(val); - } - } -}; - - -/** - * @return {boolean} Whether the test was a success. - */ -goog.testing.TestCase.prototype.isSuccess = function() { - return !!this.result_ && this.result_.isSuccess(); -}; - - -/** - * Returns a string detailing the results from the test. - * @param {boolean=} opt_verbose If true results will include data about all - * tests, not just what failed. - * @return {string} The results from the test. - */ -goog.testing.TestCase.prototype.getReport = function(opt_verbose) { - var rv = []; - if (this.testRunner_ && !this.testRunner_.isFinished()) { - rv.push(this.name_ + ' [RUNNING]'); - } else { - var success = this.result_.isSuccess() && !this.testRunner_.hasErrors(); - rv.push(this.name_ + ' [' + (success ? 'PASSED' : 'FAILED') + ']'); - } - rv.push(this.trimPath_(window.location.href)); - rv.push(this.result_.getSummary()); - if (opt_verbose) { - rv.push('.', this.result_.messages.join('\n')); - } else if (!this.result_.isSuccess()) { - rv.push(this.result_.errors.join('\n')); - } - rv.push(' '); - return rv.join('\n'); -}; - - -/** - * Returns the amount of time it took for the test to run. - * @return {number} The run time, in milliseconds. - */ -goog.testing.TestCase.prototype.getRunTime = function() { - return this.result_.runTime; -}; - - -/** - * Returns the number of script files that were loaded in order to run the test. - * @return {number} The number of script files. - */ -goog.testing.TestCase.prototype.getNumFilesLoaded = function() { - return this.result_.numFilesLoaded; -}; - - -/** - * Executes each of the tests. - * Overridable by the individual test case. This allows test cases to defer - * when the test is actually started. If overridden, finalize must be called - * by the test to indicate it has finished. - */ -goog.testing.TestCase.prototype.runTests = function() { - this.setUpPage(); - this.execute(); -}; - - -/** - * Reorders the tests depending on the {@code order} field. - * @param {Array.<goog.testing.TestCase.Test>} tests An array of tests to - * reorder. - * @private - */ -goog.testing.TestCase.prototype.orderTests_ = function(tests) { - switch (this.order) { - case goog.testing.TestCase.Order.RANDOM: - // Fisher-Yates shuffle - var i = tests.length; - while (i > 1) { - // goog.math.randomInt is inlined to reduce dependencies. - var j = Math.floor(Math.random() * i); // exclusive - i--; - var tmp = tests[i]; - tests[i] = tests[j]; - tests[j] = tmp; - } - break; - - case goog.testing.TestCase.Order.SORTED: - tests.sort(function(t1, t2) { - if (t1.name == t2.name) { - return 0; - } - return t1.name < t2.name ? -1 : 1; - }); - break; - - // Do nothing for NATURAL. - } -}; - - -/** - * Gets the object with all globals. - * @param {string=} opt_prefix An optional prefix. If specified, only get things - * under this prefix. - * @return {Object} An object with all globals starting with the prefix. - */ -goog.testing.TestCase.prototype.getGlobals = function(opt_prefix) { - return goog.testing.TestCase.getGlobals(opt_prefix); -}; - - -/** - * Gets the object with all globals. - * @param {string=} opt_prefix An optional prefix. If specified, only get things - * under this prefix. - * @return {Object} An object with all globals starting with the prefix. - */ -goog.testing.TestCase.getGlobals = function(opt_prefix) { - // Look in the global scope for most browsers, on IE we use the little known - // RuntimeObject which holds references to all globals. We reference this - // via goog.global so that there isn't an aliasing that throws an exception - // in Firefox. - return typeof goog.global['RuntimeObject'] != 'undefined' ? - goog.global['RuntimeObject']((opt_prefix || '') + '*') : goog.global; -}; - - -/** - * Gets called before any tests are executed. Can be overridden to set up the - * environment for the whole test case. - */ -goog.testing.TestCase.prototype.setUpPage = function() {}; - - -/** - * Gets called after all tests have been executed. Can be overridden to tear - * down the entire test case. - */ -goog.testing.TestCase.prototype.tearDownPage = function() {}; - - -/** - * Gets called before every goog.testing.TestCase.Test is been executed. Can be - * overridden to add set up functionality to each test. - */ -goog.testing.TestCase.prototype.setUp = function() {}; - - -/** - * Gets called after every goog.testing.TestCase.Test has been executed. Can be - * overriden to add tear down functionality to each test. - */ -goog.testing.TestCase.prototype.tearDown = function() {}; - - -/** - * @return {string} The function name prefix used to auto-discover tests. - * @protected - */ -goog.testing.TestCase.prototype.getAutoDiscoveryPrefix = function() { - return 'test'; -}; - - -/** - * @return {number} Time since the last batch of tests was started. - * @protected - */ -goog.testing.TestCase.prototype.getBatchTime = function() { - return this.batchTime_; -}; - - -/** - * @param {number} batchTime Time since the last batch of tests was started. - * @protected - */ -goog.testing.TestCase.prototype.setBatchTime = function(batchTime) { - this.batchTime_ = batchTime; -}; - - -/** - * Creates a {@code goog.testing.TestCase.Test} from an auto-discovered - * function. - * @param {string} name The name of the function. - * @param {function() : void} ref The auto-discovered function. - * @return {goog.testing.TestCase.Test} The newly created test. - * @protected - */ -goog.testing.TestCase.prototype.createTestFromAutoDiscoveredFunction = - function(name, ref) { - return new goog.testing.TestCase.Test(name, ref, goog.global); -}; - - -/** - * Adds any functions defined in the global scope that are prefixed with "test" - * to the test case. Also overrides setUp, tearDown, setUpPage, tearDownPage - * and runTests if they are defined. - */ -goog.testing.TestCase.prototype.autoDiscoverTests = function() { - var prefix = this.getAutoDiscoveryPrefix(); - var testSource = this.getGlobals(prefix); - - var foundTests = []; - - for (var name in testSource) { - - try { - var ref = testSource[name]; - } catch (ex) { - // NOTE(user): When running tests from a file:// URL on Firefox 3.5 - // for Windows, any reference to window.sessionStorage raises - // an "Operation is not supported" exception. Ignore any exceptions raised - // by simply accessing global properties. - } - - if ((new RegExp('^' + prefix)).test(name) && goog.isFunction(ref)) { - foundTests.push(this.createTestFromAutoDiscoveredFunction(name, ref)); - } - } - - this.orderTests_(foundTests); - - for (var i = 0; i < foundTests.length; i++) { - this.add(foundTests[i]); - } - - this.log(this.getCount() + ' tests auto-discovered'); - - if (goog.global['setUp']) { - this.setUp = goog.bind(goog.global['setUp'], goog.global); - } - if (goog.global['tearDown']) { - this.tearDown = goog.bind(goog.global['tearDown'], goog.global); - } - if (goog.global['setUpPage']) { - this.setUpPage = goog.bind(goog.global['setUpPage'], goog.global); - } - if (goog.global['tearDownPage']) { - this.tearDownPage = goog.bind(goog.global['tearDownPage'], goog.global); - } - if (goog.global['runTests']) { - this.runTests = goog.bind(goog.global['runTests'], goog.global); - } - if (goog.global['shouldRunTests']) { - this.shouldRunTests = goog.bind(goog.global['shouldRunTests'], goog.global); - } -}; - - -/** - * Cycles through the tests, breaking out using a setTimeout if the execution - * time has execeeded {@link #MAX_RUN_TIME}. - */ -goog.testing.TestCase.prototype.cycleTests = function() { - this.saveMessage('Start'); - this.batchTime_ = this.now_(); - var nextTest; - while ((nextTest = this.next()) && this.running) { - this.result_.runCount++; - // Execute the test and handle the error, we execute all tests rather than - // stopping after a single error. - var cleanedUp = false; - - try { - this.log('Running test: ' + nextTest.name); - - goog.testing.TestCase.currentTestName = nextTest.name; - this.setUp(); - nextTest.execute(); - this.tearDown(); - goog.testing.TestCase.currentTestName = null; - - cleanedUp = true; - - this.doSuccess(nextTest); - } catch (e) { - this.doError(nextTest, e); - - if (!cleanedUp) { - try { - this.tearDown(); - } catch (e2) {} // Fail silently if tearDown is throwing the errors. - } - } - - // If the max run time is exceeded call this function again async so as not - // to block the browser. - if (this.currentTestPointer_ < this.tests_.length && - this.now_() - this.batchTime_ > goog.testing.TestCase.MAX_RUN_TIME) { - this.saveMessage('Breaking async'); - this.timeout(goog.bind(this.cycleTests, this), 100); - return; - } - } - // Tests are done. - this.finalize(); -}; - - -/** - * Counts the number of files that were loaded for dependencies that are - * required to run the test. - * @return {number} The number of files loaded. - * @private - */ -goog.testing.TestCase.prototype.countNumFilesLoaded_ = function() { - var scripts = document.getElementsByTagName('script'); - var count = 0; - for (var i = 0, n = scripts.length; i < n; i++) { - if (scripts[i].src) { - count++; - } - } - return count; -}; - - -/** - * Calls a function after a delay, using the protected timeout. - * @param {Function} fn The function to call. - * @param {number} time Delay in milliseconds. - * @return {number} The timeout id. - * @protected - */ -goog.testing.TestCase.prototype.timeout = function(fn, time) { - var protectedTimeout = goog.testing.TestCase.protectedTimeout_; - return protectedTimeout(fn, time); -}; - - -/** - * @return {number} The current time in milliseconds, don't use goog.now as some - * tests override it. - * @private - */ -goog.testing.TestCase.prototype.now_ = function() { - return new Date().getTime(); -}; - - -/** - * Returns the current time. - * @return {string} HH:MM:SS. - * @private - */ -goog.testing.TestCase.prototype.getTimeStamp_ = function() { - var d = new Date; - - // Ensure millis are always 3-digits - var millis = '00' + d.getMilliseconds(); - millis = millis.substr(millis.length - 3); - - return this.pad_(d.getHours()) + ':' + this.pad_(d.getMinutes()) + ':' + - this.pad_(d.getSeconds()) + '.' + millis; -}; - - -/** - * Pads a number to make it have a leading zero if it's less than 10. - * @param {number} number The number to pad. - * @return {string} The resulting string. - * @private - */ -goog.testing.TestCase.prototype.pad_ = function(number) { - return number < 10 ? '0' + number : String(number); -}; - - -/** - * Trims a path to be only that after google3. - * @param {string} path The path to trim. - * @return {string} The resulting string. - * @private - */ -goog.testing.TestCase.prototype.trimPath_ = function(path) { - return path.substring(path.indexOf('google3') + 8); -}; - - -/** - * Handles a test that passed. - * @param {goog.testing.TestCase.Test} test The test that passed. - * @protected - */ -goog.testing.TestCase.prototype.doSuccess = function(test) { - this.result_.successCount++; - var message = test.name + ' : PASSED'; - this.saveMessage(message); - this.log(message); -}; - - -/** - * Handles a test that failed. - * @param {goog.testing.TestCase.Test} test The test that failed. - * @param {*=} opt_e The exception object associated with the - * failure or a string. - * @protected - */ -goog.testing.TestCase.prototype.doError = function(test, opt_e) { - var message = test.name + ' : FAILED'; - this.log(message); - this.saveMessage(message); - var err = this.logError(test.name, opt_e); - this.result_.errors.push(err); -}; - - -/** - * @param {string} name Failed test name. - * @param {*=} opt_e The exception object associated with the - * failure or a string. - * @return {goog.testing.TestCase.Error} Error object. - */ -goog.testing.TestCase.prototype.logError = function(name, opt_e) { - var errMsg = null; - var stack = null; - if (opt_e) { - this.log(opt_e); - if (goog.isString(opt_e)) { - errMsg = opt_e; - } else { - errMsg = opt_e.message || opt_e.description || opt_e.toString(); - stack = opt_e.stack ? goog.testing.stacktrace.canonicalize(opt_e.stack) : - opt_e['stackTrace']; - } - } else { - errMsg = 'An unknown error occurred'; - } - var err = new goog.testing.TestCase.Error(name, errMsg, stack); - - // Avoid double logging. - if (!opt_e || !opt_e['isJsUnitException'] || - !opt_e['loggedJsUnitException']) { - this.saveMessage(err.toString()); - } - if (opt_e && opt_e['isJsUnitException']) { - opt_e['loggedJsUnitException'] = true; - } - - return err; -}; - - - -/** - * A class representing a single test function. - * @param {string} name The test name. - * @param {Function} ref Reference to the test function. - * @param {Object=} opt_scope Optional scope that the test function should be - * called in. - * @constructor - */ -goog.testing.TestCase.Test = function(name, ref, opt_scope) { - /** - * The name of the test. - * @type {string} - */ - this.name = name; - - /** - * Reference to the test function. - * @type {Function} - */ - this.ref = ref; - - /** - * Scope that the test function should be called in. - * @type {Object} - */ - this.scope = opt_scope || null; -}; - - -/** - * Executes the test function. - */ -goog.testing.TestCase.Test.prototype.execute = function() { - this.ref.call(this.scope); -}; - - - -/** - * A class for representing test results. A bag of public properties. - * @param {goog.testing.TestCase} testCase The test case that owns this result. - * @constructor - */ -goog.testing.TestCase.Result = function(testCase) { - - /** - * The test case that owns this result. - * @type {goog.testing.TestCase} - * @private - */ - this.testCase_ = testCase; - - /** - * Total number of tests that should have been run. - * @type {number} - */ - this.totalCount = 0; - - /** - * Total number of tests that were actually run. - * @type {number} - */ - this.runCount = 0; - - /** - * Number of successful tests. - * @type {number} - */ - this.successCount = 0; - - /** - * The amount of time the tests took to run. - * @type {number} - */ - this.runTime = 0; - - /** - * The number of files loaded to run this test. - * @type {number} - */ - this.numFilesLoaded = 0; - - /** - * Whether this test case was suppressed by shouldRunTests() returning false. - * @type {boolean} - */ - this.testSuppressed = false; - - /** - * Errors encountered while running the test. - * @type {Array.<goog.testing.TestCase.Error>} - */ - this.errors = []; - - /** - * Messages to show the user after running the test. - * @type {Array.<string>} - */ - this.messages = []; -}; - - -/** - * @return {boolean} Whether the test was successful. - */ -goog.testing.TestCase.Result.prototype.isSuccess = function() { - var noErrors = this.runCount == this.successCount && this.errors.length == 0; - if (noErrors && !this.testSuppressed && this.isStrict()) { - return this.runCount > 0; - } - return noErrors; -}; - - -/** - * @return {string} A summary of the tests, including total number of tests that - * passed, failed, and the time taken. - */ -goog.testing.TestCase.Result.prototype.getSummary = function() { - var summary = this.runCount + ' of ' + this.totalCount + ' tests run in ' + - this.runTime + 'ms.\n'; - if (this.testSuppressed) { - summary += 'Tests not run because shouldRunTests() returned false.'; - } else if (this.runCount == 0) { - summary += 'No tests found. '; - if (this.isStrict()) { - summary += - 'Call G_testRunner.setStrict(false) if this is expected behavior. '; - } - } else { - summary += this.successCount + ' passed, ' + - (this.totalCount - this.successCount) + ' failed.\n' + - Math.round(this.runTime / this.runCount) + ' ms/test. ' + - this.numFilesLoaded + ' files loaded.'; - } - - return summary; -}; - - -/** - * Initializes the given test case with the global test runner 'G_testRunner'. - * @param {goog.testing.TestCase} testCase The test case to install. - */ -goog.testing.TestCase.initializeTestRunner = function(testCase) { - testCase.autoDiscoverTests(); - var gTestRunner = goog.global['G_testRunner']; - if (gTestRunner) { - gTestRunner['initialize'](testCase); - } else { - throw Error('G_testRunner is undefined. Please ensure goog.testing.jsunit' + - 'is included.'); - } -}; - - -/** - * Determines whether the test result should report failure if no tests are run. - * @return {boolean} Whether this is strict. - */ -goog.testing.TestCase.Result.prototype.isStrict = function() { - return this.testCase_.testRunner_.isStrict(); -}; - - - -/** - * A class representing an error thrown by the test - * @param {string} source The name of the test which threw the error. - * @param {string} message The error message. - * @param {string=} opt_stack A string showing the execution stack. - * @constructor - */ -goog.testing.TestCase.Error = function(source, message, opt_stack) { - /** - * The name of the test which threw the error. - * @type {string} - */ - this.source = source; - - /** - * Reference to the test function. - * @type {string} - */ - this.message = message; - - /** - * Scope that the test function should be called in. - * @type {?string} - */ - this.stack = opt_stack || null; -}; - - -/** - * Returns a string representing the error object. - * @return {string} A string representation of the error. - */ -goog.testing.TestCase.Error.prototype.toString = function() { - return 'ERROR in ' + this.source + '\n' + - this.message + (this.stack ? '\n' + this.stack : ''); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testqueue.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testqueue.js.svn-base deleted file mode 100644 index e070130..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testqueue.js.svn-base +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Generic queue for writing unit tests. - */ - -goog.provide('goog.testing.TestQueue'); - - - -/** - * Generic queue for writing unit tests - * @constructor - */ -goog.testing.TestQueue = function() { - /** - * Events that have accumulated - * @type {Array.<Object>} - * @private - */ - this.events_ = []; -}; - - -/** - * Adds a new event onto the queue. - * @param {Object} event The event to queue. - */ -goog.testing.TestQueue.prototype.enqueue = function(event) { - this.events_.push(event); -}; - - -/** - * Returns whether the queue is empty. - * @return {boolean} Whether the queue is empty. - */ -goog.testing.TestQueue.prototype.isEmpty = function() { - return this.events_.length == 0; -}; - - -/** - * Gets the next event from the queue. Throws an exception if the queue is - * empty. - * @param {string=} opt_comment Comment if the queue is empty. - * @return {Object} The next event from the queue. - */ -goog.testing.TestQueue.prototype.dequeue = function(opt_comment) { - if (this.isEmpty()) { - throw Error('Handler is empty: ' + opt_comment); - } - return this.events_.shift(); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testrunner.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testrunner.js.svn-base deleted file mode 100644 index a80743a..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/.svn/text-base/testrunner.js.svn-base +++ /dev/null @@ -1,391 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview The test runner is a singleton object that is used to execute - * a goog.testing.TestCases, display the results, and expose the results to - * Selenium for automation. If a TestCase hasn't been registered with the - * runner by the time window.onload occurs, the testRunner will try to auto- - * discover JsUnit style test pages. - * - * The hooks for selenium are :- - * - Boolean G_testRunner.isFinished() - * - Boolean G_testRunner.isSuccess() - * - String G_testRunner.getReport() - * - number G_testRunner.getRunTime() - * - * Testing code should not have dependencies outside of goog.testing so as to - * reduce the chance of masking missing dependencies. - * - */ - -goog.provide('goog.testing.TestRunner'); - -goog.require('goog.testing.TestCase'); - - - -/** - * Construct a test runner. - * - * NOTE(user): This is currently pretty weird, I'm essentially trying to - * create a wrapper that the Selenium test can hook into to query the state of - * the running test case, while making goog.testing.TestCase general. - * - * @constructor - */ -goog.testing.TestRunner = function() { - /** - * Errors that occurred in the window. - * @type {Array.<string>} - */ - this.errors = []; -}; - - -/** - * Reference to the active test case. - * @type {goog.testing.TestCase?} - */ -goog.testing.TestRunner.prototype.testCase = null; - - -/** - * Whether the test runner has been initialized yet. - * @type {boolean} - */ -goog.testing.TestRunner.prototype.initialized = false; - - -/** - * Element created in the document to add test results to. - * @type {Element} - * @private - */ -goog.testing.TestRunner.prototype.logEl_ = null; - - -/** - * Function to use when filtering errors. - * @type {(function(string))?} - * @private - */ -goog.testing.TestRunner.prototype.errorFilter_ = null; - - -/** - * Whether an empty test case counts as an error. - * @type {boolean} - * @private - */ -goog.testing.TestRunner.prototype.strict_ = true; - - -/** - * Initializes the test runner. - * @param {goog.testing.TestCase} testCase The test case to initialize with. - */ -goog.testing.TestRunner.prototype.initialize = function(testCase) { - if (!this.logEl_) { - var el = document.getElementById('closureTestRunnerLog'); - if (el == null) { - el = document.createElement('div'); - document.body.appendChild(el); - } - this.logEl_ = el; - } - - if (this.testCase && this.testCase.running) { - throw Error('The test runner is already waiting for a test to complete'); - } - this.testCase = testCase; - testCase.setTestRunner(this); - this.initialized = true; -}; - - -/** - * By default, the test runner is strict, and fails if it runs an empty - * test case. - * @param {boolean} strict Whether the test runner should fail on an empty - * test case. - */ -goog.testing.TestRunner.prototype.setStrict = function(strict) { - this.strict_ = strict; -}; - - -/** - * @return {boolean} Whether the test runner should fail on an empty - * test case. - */ -goog.testing.TestRunner.prototype.isStrict = function() { - return this.strict_; -}; - - -/** - * Returns true if the test runner is initialized. - * Used by Selenium Hooks. - * @return {boolean} Whether the test runner is active. - */ -goog.testing.TestRunner.prototype.isInitialized = function() { - return this.initialized; -}; - - -/** - * Returns true if the test runner is finished. - * Used by Selenium Hooks. - * @return {boolean} Whether the test runner is active. - */ -goog.testing.TestRunner.prototype.isFinished = function() { - return this.errors.length > 0 || - this.initialized && !!this.testCase && this.testCase.started && - !this.testCase.running; -}; - - -/** - * Returns true if the test case didn't fail. - * Used by Selenium Hooks. - * @return {boolean} Whether the current test returned successfully. - */ -goog.testing.TestRunner.prototype.isSuccess = function() { - return !this.hasErrors() && !!this.testCase && this.testCase.isSuccess(); -}; - - -/** - * Returns true if the test case runner has errors that were caught outside of - * the test case. - * @return {boolean} Whether there were JS errors. - */ -goog.testing.TestRunner.prototype.hasErrors = function() { - return this.errors.length > 0; -}; - - -/** - * Logs an error that occurred. Used in the case of environment setting up - * an onerror handler. - * @param {string} msg Error message. - */ -goog.testing.TestRunner.prototype.logError = function(msg) { - if (!this.errorFilter_ || this.errorFilter_.call(null, msg)) { - this.errors.push(msg); - } -}; - - -/** - * Log failure in current running test. - * @param {Error} ex Exception. - */ -goog.testing.TestRunner.prototype.logTestFailure = function(ex) { - var testName = /** @type {string} */ goog.testing.TestCase.currentTestName; - if (this.testCase) { - this.testCase.logError(testName, ex); - } else { - // NOTE: Do not forget to log the original exception raised. - throw new Error('Test runner not initialized with a test case. Original ' + - 'exception: ' + ex.message); - } -}; - - -/** - * Sets a function to use as a filter for errors. - * @param {function(string)} fn Filter function. - */ -goog.testing.TestRunner.prototype.setErrorFilter = function(fn) { - this.errorFilter_ = fn; -}; - - -/** - * Returns a report of the test case that ran. - * Used by Selenium Hooks. - * @param {boolean=} opt_verbose If true results will include data about all - * tests, not just what failed. - * @return {string} A report summary of the test. - */ -goog.testing.TestRunner.prototype.getReport = function(opt_verbose) { - var report = []; - if (this.testCase) { - report.push(this.testCase.getReport(opt_verbose)); - } - if (this.errors.length > 0) { - report.push('JavaScript errors detected by test runner:'); - report.push.apply(report, this.errors); - report.push('\n'); - } - return report.join('\n'); -}; - - -/** - * Returns the amount of time it took for the test to run. - * Used by Selenium Hooks. - * @return {number} The run time, in milliseconds. - */ -goog.testing.TestRunner.prototype.getRunTime = function() { - return this.testCase ? this.testCase.getRunTime() : 0; -}; - - -/** - * Returns the number of script files that were loaded in order to run the test. - * @return {number} The number of script files. - */ -goog.testing.TestRunner.prototype.getNumFilesLoaded = function() { - return this.testCase ? this.testCase.getNumFilesLoaded() : 0; -}; - - -/** - * Executes a test case and prints the results to the window. - */ -goog.testing.TestRunner.prototype.execute = function() { - if (!this.testCase) { - throw Error('The test runner must be initialized with a test case before ' + - 'execute can be called.'); - } - this.testCase.setCompletedCallback(goog.bind(this.onComplete_, this)); - this.testCase.runTests(); -}; - - -/** - * Writes the results to the document when the test case completes. - * @private - */ -goog.testing.TestRunner.prototype.onComplete_ = function() { - var log = this.testCase.getReport(true); - if (this.errors.length > 0) { - log += '\n' + this.errors.join('\n'); - } - - // Remove all children from the log element. - var logEl = this.logEl_; - while (logEl.firstChild) { - logEl.removeChild(logEl.firstChild); - } - - this.writeLog(log); - - var runAgainLink = document.createElement('a'); - runAgainLink.style.display = 'block'; - runAgainLink.style.fontSize = 'small'; - runAgainLink.href = ''; - runAgainLink.onclick = goog.bind(function() { - this.execute(); - return false; - }, this); - runAgainLink.innerHTML = 'Run again without reloading'; - logEl.appendChild(runAgainLink); -}; - - -/** - * Writes a nicely formatted log out to the document. - * @param {string} log The string to write. - */ -goog.testing.TestRunner.prototype.writeLog = function(log) { - var lines = log.split('\n'); - for (var i = 0; i < lines.length; i++) { - var line = lines[i]; - var color; - var isFailOrError = /FAILED/.test(line) || /ERROR/.test(line); - if (/PASSED/.test(line)) { - color = 'darkgreen'; - } else if (isFailOrError) { - color = 'darkred'; - } else { - color = '#333'; - } - var div = document.createElement('div'); - if (line.substr(0, 2) == '> ') { - // The stack trace may contain links so it has to be interpreted as HTML. - div.innerHTML = line; - } else { - div.appendChild(document.createTextNode(line)); - } - - if (isFailOrError) { - var testNameMatch = /(\S+) (\[[^\]]*] )?: (FAILED|ERROR)/.exec(line); - if (testNameMatch) { - // Build a URL to run the test individually. If this test was already - // part of another subset test, we need to overwrite the old runTests - // query parameter. We also need to do this without bringing in any - // extra dependencies, otherwise we could mask missing dependency bugs. - var newSearch = 'runTests=' + testNameMatch[1]; - var search = window.location.search; - if (search) { - var oldTests = /runTests=([^&]*)/.exec(search); - if (oldTests) { - newSearch = search.substr(0, oldTests.index) + - newSearch + - search.substr(oldTests.index + oldTests[0].length); - } else { - newSearch = search + '&' + newSearch; - } - } else { - newSearch = '?' + newSearch; - } - var href = window.location.href; - var hash = window.location.hash; - if (hash && hash.charAt(0) != '#') { - hash = '#' + hash; - } - href = href.split('#')[0].split('?')[0] + newSearch + hash; - - // Add the link. - var a = document.createElement('A'); - a.innerHTML = '(run individually)'; - a.style.fontSize = '0.8em'; - a.href = href; - div.appendChild(document.createTextNode(' ')); - div.appendChild(a); - } - } - - div.style.color = color; - div.style.font = 'normal 100% monospace'; - - try { - div.style.whiteSpace = 'pre-wrap'; - } catch (e) { - // NOTE(user): IE raises an exception when assigning to pre-wrap. - // Thankfully, it doesn't collapse whitespace when using monospace fonts, - // so it will display correctly if we ignore the exception. - } - - if (i < 2) { - div.style.fontWeight = 'bold'; - } - this.logEl_.appendChild(div); - } -}; - - -/** - * Logs a message to the current test case. - * @param {string} s The text to output to the log. - */ -goog.testing.TestRunner.prototype.log = function(s) { - if (this.testCase) { - this.testCase.log(s); - } -}; |