Index: chrome/test/data/webui/assertions.js |
diff --git a/chrome/test/data/webui/assertions.js b/chrome/test/data/webui/assertions.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ebeadfd3d94128f02acc305df350a2d178fbf356 |
--- /dev/null |
+++ b/chrome/test/data/webui/assertions.js |
@@ -0,0 +1,86 @@ |
+// 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. |
+ |
+function WebUIAssertionsTest() {} |
+ |
+WebUIAssertionsTest.prototype = { |
+ __proto__: testing.Test.prototype, |
+ browsePreload: 'chrome://DummyURL', |
+ typedefCppFixture: null, |
+}; |
+ |
+GEN('#include "chrome/browser/ui/webui/chrome_web_ui.h"'); |
+GEN('#include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"'); |
+GEN('#include "googleurl/src/gurl.h"'); |
+GEN('#include "testing/gmock/include/gmock/gmock.h"'); |
+GEN(''); |
+GEN('using ::testing::_;'); |
+GEN('using ::testing::Eq;'); |
+GEN('using ::testing::StrictMock;'); |
+GEN(''); |
+GEN('// Dummy URL location for us to override.'); |
+GEN('const char kDummyURL[] = "chrome://DummyURL/";'); |
+GEN(''); |
+GEN('// Returns a new WebUI object for the TabContents from |arg0|.'); |
+GEN('ACTION(ReturnNewWebUI) {'); |
+GEN(' return new ChromeWebUI(arg0);'); |
+GEN('}'); |
+GEN(''); |
+GEN('// Mock the TestChromeWebUIFactory::WebUIProvider to prove that ' + |
+ 'we are called as'); |
+GEN('// expected.'); |
+GEN('class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider {'); |
+GEN(' public:'); |
+GEN(' MOCK_METHOD2(NewWebUI, WebUI*(TabContents* tab_contents, const GURL& ' + |
+ 'url));'); |
+GEN('};'); |
+GEN(''); |
+GEN('class WebUIAssertionsTest : public WebUIBrowserTest {'); |
+GEN(' public:'); |
+GEN(' virtual void SetUpOnMainThread() OVERRIDE {'); |
+GEN(' WebUIBrowserTest::SetUpOnMainThread();'); |
+GEN(' TestChromeWebUIFactory::AddFactoryOverride('); |
+GEN(' GURL(kDummyURL).host(), &mock_provider_);'); |
+GEN(' EXPECT_CALL(mock_provider_, NewWebUI(_, Eq(GURL(kDummyURL))))'); |
+GEN(' .WillOnce(ReturnNewWebUI());'); |
+GEN(' }'); |
+GEN(' virtual void CleanUpOnMainThread() OVERRIDE {'); |
+GEN(' WebUIBrowserTest::CleanUpOnMainThread();'); |
+GEN(' TestChromeWebUIFactory::RemoveFactoryOverride('); |
+GEN(' GURL(kDummyURL).host());'); |
+GEN(' }'); |
+GEN(''); |
+GEN(' StrictMock<MockWebUIProvider> mock_provider_;'); |
+GEN(''); |
+GEN('};'); |
+ |
+TEST_F('WebUIAssertionsTest', 'testTwoExpects', function() { |
+ var result = runTest( |
+ function() { |
+ expectTrue(false); |
+ expectTrue(0); |
+ }, []); |
+ |
+ expectFalse(result[0]); |
+ expectTrue(!!result[1].match(/expectTrue\(false\): false/)); |
+ expectTrue(!!result[1].match(/expectTrue\(0\): 0/)); |
+}); |
+ |
+function twoExpects() { |
+ expectTrue(false, 'message1'); |
+ expectTrue(false, 'message2'); |
+} |
+ |
+TEST_F('WebUIAssertionsTest', 'testCallTestTwice', function() { |
+ var result = runTest( |
+ function() { |
+ twoExpects(); |
+ twoExpects(); |
+ }, []); |
+ expectFalse(result[0]); |
+ expectEquals( |
+ 2, result[1].match(/expectTrue\(false, 'message1'\): false/g).length); |
+ expectEquals( |
+ 2, result[1].match(/expectTrue\(false, 'message2'\): false/g).length); |
+}); |