Added options browser_tests using the generator and js handler framework.

This patch turned out to be fairly large.  Let me describe the ultimate goal:
- To write WebUI tests in javascript, with as little C++ as possible for the simple case, yet powerful enough to support more complicated cases.  options.js illustrates the simple case, and print_preview.js illustrates the complicated case.

Original changes:
- Refactored test_tab_strip_observer into test_navigation_observer so that it could be used by itself without needing the TabInsertedAt logic, which PrintPreview needs when there's no TabContentsWrapper available.
- Added assertEqualsArray for comparing two arrays shallowly (javascript == fails).
- Provided logic in WebUIBrowserTest and in the javascript2webui.js generation script to allow browsing to a url with preload of injected javascript.
- Corrected test_navigation_observer to wait for the right notification before calling callback (which runs after the page's javascript is loaded but before its onload).
- Added guts to define OS_* ifdefs for javascript to test for disabling tests.
- Moved the handler from settings_browsertest.cc to settings.js
- use __proto__ when overriding chrome to allow other members to be seen (commandLineString, e.g.)

Additions made during review:
- Switched to generative mechanism: TEST_F, GEN, which output during generation, and register during runtime.
- JS fixtures provide configuration members
- Add configuration hooks to generate in C++ test function
- Output directly to .cc file rather than needing hand-made .cc file which includes the generated file.
- Changed preload to take testFixture and testName.
- include and use mock4js to ensure handler methods are called.
- auto-generate the typedef WebUIBrowserTest testFixture unless overridden.

[email protected],[email protected]
BUG=None
TEST=browser_tests --gtest_filter=SettingsWebUITest.*

Review URL: http://codereview.chromium.org/7237030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92084 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/test/test_navigation_observer.cc b/chrome/test/test_navigation_observer.cc
new file mode 100644
index 0000000..b7bcc74
--- /dev/null
+++ b/chrome/test/test_navigation_observer.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/test_navigation_observer.h"
+
+#include "chrome/test/ui_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TestNavigationObserver::JsInjectionReadyObserver::JsInjectionReadyObserver() {
+}
+
+TestNavigationObserver::JsInjectionReadyObserver::~JsInjectionReadyObserver() {
+}
+
+TestNavigationObserver::TestNavigationObserver(
+    NavigationController* controller,
+    TestNavigationObserver::JsInjectionReadyObserver*
+        js_injection_ready_observer,
+    int number_of_navigations)
+    : navigation_started_(false),
+      navigation_entry_committed_(false),
+      navigations_completed_(0),
+      number_of_navigations_(number_of_navigations),
+      js_injection_ready_observer_(js_injection_ready_observer),
+      done_(false),
+      running_(false) {
+  RegisterAsObserver(controller);
+}
+
+TestNavigationObserver::TestNavigationObserver(
+    TestNavigationObserver::JsInjectionReadyObserver*
+        js_injection_ready_observer,
+    int number_of_navigations)
+    : navigation_started_(false),
+      navigations_completed_(0),
+      number_of_navigations_(number_of_navigations),
+      js_injection_ready_observer_(js_injection_ready_observer),
+      done_(false),
+      running_(false) {
+}
+
+TestNavigationObserver::~TestNavigationObserver() {
+}
+
+void TestNavigationObserver::RegisterAsObserver(
+    NavigationController* controller) {
+  registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+                 Source<NavigationController>(controller));
+  registrar_.Add(this, content::NOTIFICATION_LOAD_START,
+                 Source<NavigationController>(controller));
+  registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
+                 Source<NavigationController>(controller));
+}
+
+void TestNavigationObserver::WaitForObservation() {
+  if (!done_) {
+    EXPECT_FALSE(running_);
+    running_ = true;
+    ui_test_utils::RunMessageLoop();
+  }
+}
+
+void TestNavigationObserver::Observe(
+    int type, const NotificationSource& source,
+    const NotificationDetails& details) {
+  if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
+    if (!navigation_entry_committed_ && js_injection_ready_observer_)
+      js_injection_ready_observer_->OnJsInjectionReady();
+    navigation_started_ = true;
+    navigation_entry_committed_ = true;
+  } else if (type == content::NOTIFICATION_LOAD_START) {
+    navigation_started_ = true;
+  } else if (type == content::NOTIFICATION_LOAD_STOP) {
+    if (navigation_started_ &&
+        ++navigations_completed_ == number_of_navigations_) {
+      navigation_started_ = false;
+      done_ = true;
+      if (running_)
+        MessageLoopForUI::current()->Quit();
+    }
+  }
+}