| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Budget API: Make basic getBudget call.</title> | 4 <title>Budget API: Make basic getBudget call.</title> |
| 5 <script src="../resources/testharness.js"></script> | 5 <script src="../resources/testharness.js"></script> |
| 6 <script src="../resources/testharnessreport.js"></script> | 6 <script src="../resources/testharnessreport.js"></script> |
| 7 <script src="/js-test-resources/mojo-helpers.js"></script> | 7 <script src="/js-test-resources/mojo-helpers.js"></script> |
| 8 <script src="budget-service-mock.js"></script> | 8 <script src="budget-service-mock.js"></script> |
| 9 </head> | 9 </head> |
| 10 <body> | 10 <body> |
| 11 <script> | 11 <script> |
| 12 if (!window.mojo) | |
| 13 debug('This test can not run without mojo'); | |
| 14 | |
| 15 promise_test(function() { | 12 promise_test(function() { |
| 16 return budgetServiceMock.then(mock => { | 13 return budgetServiceMock.then(mock => { |
| 17 assert_own_property(Navigator.prototype, 'budget'); | 14 assert_own_property(Navigator.prototype, 'budget'); |
| 18 mock.addBudget(TEST_BUDGET_TIME, TEST_BUDGET_AT); | 15 mock.addBudget(TEST_BUDGET_TIME, TEST_BUDGET_AT); |
| 19 return navigator.budget.getBudget(); | 16 return navigator.budget.getBudget(); |
| 20 }).then(budget => { | 17 }).then(budget => { |
| 21 assert_equals(budget.length, 1); | 18 assert_equals(budget.length, 1); |
| 22 assert_equals(budget[0].budgetAt, TEST_BUDGET_AT); | 19 assert_equals(budget[0].budgetAt, TEST_BUDGET_AT); |
| 23 assert_equals(budget[0].time, TEST_BUDGET_TIME); | 20 assert_equals(budget[0].time, TEST_BUDGET_TIME); |
| 24 }); | 21 }); |
| 25 }, 'BudgetService.GetBudget should return correct results.'); | 22 }, 'BudgetService.GetBudget should return correct results.'); |
| 26 | 23 |
| 27 promise_test(function() { | 24 promise_test(function() { |
| 28 return budgetServiceMock.then(mock => { | 25 return budgetServiceMock.then(mock => { |
| 29 assert_own_property(Navigator.prototype, 'budget'); | 26 assert_own_property(Navigator.prototype, 'budget'); |
| 30 mock.setError("database-error"); | 27 mock.setError("database-error"); |
| 31 return navigator.budget.getBudget(); | 28 return navigator.budget.getBudget(); |
| 32 }).then(budget => { | 29 }).then(budget => { |
| 33 assert_unreached('getBudget should have failed.'); | 30 assert_unreached('getBudget should have failed.'); |
| 34 }, function(error) { | 31 }, function(error) { |
| 35 assert_equals(error.name, 'DataError'); | 32 assert_equals(error.name, 'DataError'); |
| 36 assert_equals(error.message, "Error reading the budget database."); | 33 assert_equals(error.message, "Error reading the budget database."); |
| 37 }); | 34 }); |
| 38 }, 'BudgetService.GetBudget should return correct results.'); | 35 }, 'BudgetService.GetBudget should return correct results.'); |
| 39 </script> | 36 </script> |
| 40 </body> | 37 </body> |
| 41 </html> | 38 </html> |
| OLD | NEW |