Temporarily disable durable storage browser test
[chromium-blink-merge.git] / chrome / third_party / mock4js / examples / PriceServiceTest.html
blobb0a35bbdc47b33b3488cd0b820b9d2132eea71ba
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
4 <html>
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7 <title>Tests</title>
8 <link rel="stylesheet" type="text/css" href="jsunit/css/jsUnitStyle.css">
9 <script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
10 <script language="JavaScript" type="text/javascript" src="../mock4js.js"></script>
11 <script language="JavaScript" type="text/javascript" src="PriceService.js"></script>
12 <script language="JavaScript" type="text/javascript">
14 Mock4JS.addMockSupport(this);
16 var mockPriceFetcher;
17 var mockPriceCache;
18 var priceService;
20 function setUp() {
21 Mock4JS.clearMocksToVerify();
22 mockPriceFetcher = mock(PriceFetcher);
23 mockPriceCache = mock(PriceCache);
24 priceService = new PriceService(mockPriceFetcher.proxy(), mockPriceCache.proxy());
27 function tearDown() {
28 Mock4JS.verifyAllMocks();
31 function testGetsPriceFromFetcherWhenPriceNotInCache() {
32 mockPriceCache.expects(once()).getCachedPrice("USDGBP").will(returnValue(null));
33 mockPriceFetcher.expects(once()).getPriceFromServer("USDGBP").will(returnValue(123.4));
34 mockPriceCache.expects(once()).setCachedPrice("USDGBP", 123.4);
36 var result = priceService.getPrice("USDGBP");
38 assertEquals("Should have returned price from server", 123.4, result);
41 function testDoesntGetsPriceFromFetcherWhenPriceAlreadyInCache() {
42 mockPriceCache.expects(once()).getCachedPrice("USDGBP").will(returnValue(123.4));
43 mockPriceCache.expects(never()).setCachedPrice();
44 mockPriceFetcher.expects(never()).getPriceFromServer("USDGBP");
46 var result = priceService.getPrice("USDGBP");
48 assertEquals("Should have returned price from cache", 123.4, result);
51 </script>
52 </head>
54 <body>
55 <h1>JsUnit Tests</h1>
57 <p>This page contains some JsUnit tests. To see them, take a look at the source.</p>
58 </body>
59 </html>