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

Unified Diff: chrome/third_party/mock4js/examples/PriceServiceTest.html

Issue 7237030: Added options browser_tests using the generator and js handler framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TestNavigationController in ui_test_utils, renamed LoadStart->JsInjectionReady, reordered methods. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/third_party/mock4js/examples/PriceServiceTest.html
diff --git a/chrome/third_party/mock4js/examples/PriceServiceTest.html b/chrome/third_party/mock4js/examples/PriceServiceTest.html
new file mode 100644
index 0000000000000000000000000000000000000000..a535aef2d192617b31dffd552fecf1b894b85db5
--- /dev/null
+++ b/chrome/third_party/mock4js/examples/PriceServiceTest.html
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Tests</title>
+ <link rel="stylesheet" type="text/css" href="jsunit/css/jsUnitStyle.css">
+ <script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
+ <script language="JavaScript" type="text/javascript" src="../mock4js.js"></script>
+ <script language="JavaScript" type="text/javascript" src="PriceService.js"></script>
+ <script language="JavaScript" type="text/javascript">
+
+ Mock4JS.addMockSupport(this);
+
+ var mockPriceFetcher;
+ var mockPriceCache;
+ var priceService;
+
+ function setUp() {
+ Mock4JS.clearMocksToVerify();
+ mockPriceFetcher = mock(PriceFetcher);
+ mockPriceCache = mock(PriceCache);
+ priceService = new PriceService(mockPriceFetcher.proxy(), mockPriceCache.proxy());
+ }
+
+ function tearDown() {
+ Mock4JS.verifyAllMocks();
+ }
+
+ function testGetsPriceFromFetcherWhenPriceNotInCache() {
+ mockPriceCache.expects(once()).getCachedPrice("USDGBP").will(returnValue(null));
+ mockPriceFetcher.expects(once()).getPriceFromServer("USDGBP").will(returnValue(123.4));
+ mockPriceCache.expects(once()).setCachedPrice("USDGBP", 123.4);
+
+ var result = priceService.getPrice("USDGBP");
+
+ assertEquals("Should have returned price from server", 123.4, result);
+ }
+
+ function testDoesntGetsPriceFromFetcherWhenPriceAlreadyInCache() {
+ mockPriceCache.expects(once()).getCachedPrice("USDGBP").will(returnValue(123.4));
+ mockPriceCache.expects(never()).setCachedPrice();
+ mockPriceFetcher.expects(never()).getPriceFromServer("USDGBP");
+
+ var result = priceService.getPrice("USDGBP");
+
+ assertEquals("Should have returned price from cache", 123.4, result);
+ }
+
+ </script>
+ </head>
+
+ <body>
+ <h1>JsUnit Tests</h1>
+
+ <p>This page contains some JsUnit tests. To see them, take a look at the source.</p>
+ </body>
+</html>
+

Powered by Google App Engine
This is Rietveld 408576698