/src/mozilla-central/toolkit/components/telemetry/tests/gtest/TelemetryFixture.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Any copyright is dedicated to the Public Domain. |
2 | | * http://creativecommons.org/publicdomain/zero/1.0/ |
3 | | */ |
4 | | |
5 | | #ifndef TelemetryFixture_h_ |
6 | | #define TelemetryFixture_h_ |
7 | | |
8 | | #include "gtest/gtest.h" |
9 | | #include "nsITelemetry.h" |
10 | | #include "mozilla/CycleCollectedJSContext.h" |
11 | | #include "mozilla/dom/ScriptSettings.h" |
12 | | |
13 | | class TelemetryTestFixture: public ::testing::Test { |
14 | | protected: |
15 | 0 | TelemetryTestFixture() : mCleanGlobal(nullptr) {} |
16 | | virtual void SetUp(); |
17 | | |
18 | | JSObject* mCleanGlobal; |
19 | | |
20 | | nsCOMPtr<nsITelemetry> mTelemetry; |
21 | | }; |
22 | | |
23 | | // AutoJSAPI is annotated with MOZ_STACK_CLASS and thus cannot be |
24 | | // used as a member of TelemetryTestFixture, since gtest instantiates |
25 | | // that on the heap. To work around the problem, use the following class |
26 | | // at the beginning of each Telemetry test. |
27 | | // Note: this is very similar to AutoJSContext, but it allows to pass a |
28 | | // global JS object in. |
29 | | class MOZ_RAII AutoJSContextWithGlobal { |
30 | | public: |
31 | | explicit AutoJSContextWithGlobal(JSObject* aGlobalObject); |
32 | | JSContext* GetJSContext() const; |
33 | | |
34 | | protected: |
35 | | mozilla::dom::AutoJSAPI mJsAPI; |
36 | | JSContext* mCx; |
37 | | }; |
38 | | |
39 | | #endif //TelemetryFixture_h_ |