Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/JsEngine.cpp

Issue 10198022: Pass application data into libadblockplus (Closed)
Patch Set: Created April 12, 2013, 1:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/info.js ('K') | « test/GlobalJsObject.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <fstream> 2 #include <fstream>
3 #include <gtest/gtest.h> 3 #include <gtest/gtest.h>
4 #include <sstream> 4 #include <sstream>
5 5
6 class ThrowingFileReader : public AdblockPlus::FileReader 6 class ThrowingFileReader : public AdblockPlus::FileReader
7 { 7 {
8 public: 8 public:
9 std::auto_ptr<std::istream> Read(const std::string& path) const 9 std::auto_ptr<std::istream> Read(const std::string& path) const
10 { 10 {
(...skipping 29 matching lines...) Expand all
40 std::ifstream* const file = new std::ifstream; 40 std::ifstream* const file = new std::ifstream;
41 file->open(""); 41 file->open("");
42 return std::auto_ptr<std::istream>(file); 42 return std::auto_ptr<std::istream>(file);
43 } 43 }
44 }; 44 };
45 45
46 TEST(JsEngineTest, EvaluateAndCall) 46 TEST(JsEngineTest, EvaluateAndCall)
47 { 47 {
48 ThrowingFileReader fileReader; 48 ThrowingFileReader fileReader;
49 ThrowingErrorCallback errorCallback; 49 ThrowingErrorCallback errorCallback;
50 AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); 50 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileReader, 0,
51 &errorCallback);
51 const std::string source = "function hello() { return 'Hello'; }"; 52 const std::string source = "function hello() { return 'Hello'; }";
52 jsEngine.Evaluate(source); 53 jsEngine.Evaluate(source);
53 const std::string result = jsEngine.Evaluate("hello()"); 54 const std::string result = jsEngine.Evaluate("hello()");
54 ASSERT_EQ("Hello", result); 55 ASSERT_EQ("Hello", result);
55 } 56 }
56 57
57 TEST(JsEngineTest, LoadAndCall) 58 TEST(JsEngineTest, LoadAndCall)
58 { 59 {
59 StubFileReader fileReader; 60 StubFileReader fileReader;
60 ThrowingErrorCallback errorCallback; 61 ThrowingErrorCallback errorCallback;
61 AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); 62 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileReader, 0,
63 &errorCallback);
62 jsEngine.Load("hello.js"); 64 jsEngine.Load("hello.js");
63 const std::string result = jsEngine.Evaluate("hello()"); 65 const std::string result = jsEngine.Evaluate("hello()");
64 ASSERT_EQ("Hello", result); 66 ASSERT_EQ("Hello", result);
65 } 67 }
66 68
67 TEST(JsEngineTest, LoadBadStreamFails) 69 TEST(JsEngineTest, LoadBadStreamFails)
68 { 70 {
69 BadFileReader fileReader; 71 BadFileReader fileReader;
70 ThrowingErrorCallback errorCallback; 72 ThrowingErrorCallback errorCallback;
71 AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); 73 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileReader, 0,
74 &errorCallback);
72 ASSERT_ANY_THROW(jsEngine.Load("hello.js")); 75 ASSERT_ANY_THROW(jsEngine.Load("hello.js"));
73 } 76 }
74 77
75 TEST(JsEngineTest, RuntimeExceptionIsThrown) 78 TEST(JsEngineTest, RuntimeExceptionIsThrown)
76 { 79 {
77 ThrowingFileReader fileReader; 80 ThrowingFileReader fileReader;
78 ThrowingErrorCallback errorCallback; 81 ThrowingErrorCallback errorCallback;
79 AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); 82 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileReader, 0,
83 &errorCallback);
80 ASSERT_THROW(jsEngine.Evaluate("doesnotexist()"), AdblockPlus::JsError); 84 ASSERT_THROW(jsEngine.Evaluate("doesnotexist()"), AdblockPlus::JsError);
81 } 85 }
82 86
83 TEST(JsEngineTest, CompileTimeExceptionIsThrown) 87 TEST(JsEngineTest, CompileTimeExceptionIsThrown)
84 { 88 {
85 ThrowingFileReader fileReader; 89 ThrowingFileReader fileReader;
86 ThrowingErrorCallback errorCallback; 90 ThrowingErrorCallback errorCallback;
87 AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); 91 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileReader, 0,
92 &errorCallback);
88 ASSERT_THROW(jsEngine.Evaluate("'foo'bar'"), AdblockPlus::JsError); 93 ASSERT_THROW(jsEngine.Evaluate("'foo'bar'"), AdblockPlus::JsError);
89 } 94 }
OLDNEW
« lib/info.js ('K') | « test/GlobalJsObject.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld