Skip to content

Commit fd0729e

Browse files
committed
Integration tests and configurations for QueryInfo support
1 parent 177ec1e commit fd0729e

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ if (IOS)
546546
${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/ad_view.h
547547
${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/interstitial_ad.h
548548
${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/internal/native_ad.h
549+
${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/internal/query_info.h
549550
${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/rewarded_ad.h
550551
${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/types.h
551552
${FIREBASE_SOURCE_DIR}/gma/src/include/firebase/gma/ump.h

gma/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ set(common_SRCS
2626
src/common/full_screen_ad_event_listener.cc
2727
src/common/native_ad.cc
2828
src/common/native_ad_internal.cc
29+
src/common/query_info.cc
30+
src/common/query_info_internal.cc
2931
src/common/rewarded_ad.cc
3032
src/common/rewarded_ad_internal.cc)
3133

@@ -49,6 +51,7 @@ set(android_SRCS
4951
src/android/interstitial_ad_internal_android.cc
5052
src/android/native_ad_image_android.cc
5153
src/android/native_ad_internal_android.cc
54+
src/android/query_info_internal_android.cc
5255
src/android/response_info_android.cc
5356
src/android/rewarded_ad_internal_android.cc)
5457

@@ -68,6 +71,7 @@ set(ios_SRCS
6871
src/ios/interstitial_ad_internal_ios.mm
6972
src/ios/native_ad_image_ios.mm
7073
src/ios/native_ad_internal_ios.mm
74+
src/ios/query_info_internal_ios.mm
7175
src/ios/response_info_ios.mm
7276
src/ios/rewarded_ad_internal_ios.mm)
7377

@@ -78,6 +82,7 @@ set(stub_SRCS
7882
src/stub/adapter_response_info_stub.cc
7983
src/stub/gma_stub.cc
8084
src/stub/native_ad_image_stub.cc
85+
src/stub/query_info_internal_stub.cc
8186
src/stub/response_info_stub.cc)
8287

8388
if(ANDROID)

gma/integration_test/src/integration_test.cc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,72 @@ TEST_F(FirebaseGmaTest, TestNativeAdLoad) {
993993
delete native_ad;
994994
}
995995

996+
TEST_F(FirebaseGmaTest, TestCreateQueryInfo) {
997+
SKIP_TEST_ON_DESKTOP;
998+
SKIP_TEST_ON_SIMULATOR;
999+
1000+
firebase::gma::QueryInfo* query_info = new firebase::gma::QueryInfo();
1001+
1002+
WaitForCompletion(query_info->Initialize(app_framework::GetWindowContext()),
1003+
"Initialize");
1004+
1005+
firebase::gma::AdRequest request = GetAdRequest();
1006+
// Set the requester type to 8. QueryInfo gets generated without a
1007+
// query_info_type set, but throws a warning that it is missing.
1008+
request.add_extra(kAdNetworkExtrasClassName, "query_info_type",
1009+
"requester_type_8");
1010+
// When the QueryInfo is initialized, generate a query info string.
1011+
firebase::Future<firebase::gma::QueryInfoResult> create_query_info_future =
1012+
query_info->CreateQueryInfo(firebase::gma::kAdFormatNative, request);
1013+
1014+
WaitForCompletion(create_query_info_future, "CreateQueryInfo");
1015+
1016+
if (create_query_info_future.error() == firebase::gma::kAdErrorCodeNone) {
1017+
const firebase::gma::QueryInfoResult* result_ptr =
1018+
create_query_info_future.result();
1019+
ASSERT_NE(result_ptr, nullptr);
1020+
EXPECT_TRUE(result_ptr->is_successful());
1021+
EXPECT_FALSE(result_ptr->query_info().empty());
1022+
}
1023+
1024+
create_query_info_future.Release();
1025+
delete query_info;
1026+
}
1027+
1028+
TEST_F(FirebaseGmaTest, TestCreateQueryInfoWithAdUnit) {
1029+
SKIP_TEST_ON_DESKTOP;
1030+
SKIP_TEST_ON_SIMULATOR;
1031+
1032+
firebase::gma::QueryInfo* query_info = new firebase::gma::QueryInfo();
1033+
1034+
WaitForCompletion(query_info->Initialize(app_framework::GetWindowContext()),
1035+
"Initialize");
1036+
1037+
firebase::gma::AdRequest request = GetAdRequest();
1038+
// Set the requester type to 8. QueryInfo gets generated without a
1039+
// query_info_type set, but throws a warning that it is missing.
1040+
request.add_extra(kAdNetworkExtrasClassName, "query_info_type",
1041+
"requester_type_8");
1042+
// When the QueryInfo is initialized, generate a query info string.
1043+
// Providing a bad/empty ad unit does not affect the query info generation.
1044+
firebase::Future<firebase::gma::QueryInfoResult> create_query_info_future =
1045+
query_info->CreateQueryInfoWithAdUnit(firebase::gma::kAdFormatNative,
1046+
request, kNativeAdUnit);
1047+
1048+
WaitForCompletion(create_query_info_future, "CreateQueryInfoWithAdUnit");
1049+
1050+
if (create_query_info_future.error() == firebase::gma::kAdErrorCodeNone) {
1051+
const firebase::gma::QueryInfoResult* result_ptr =
1052+
create_query_info_future.result();
1053+
ASSERT_NE(result_ptr, nullptr);
1054+
EXPECT_TRUE(result_ptr->is_successful());
1055+
EXPECT_FALSE(result_ptr->query_info().empty());
1056+
}
1057+
1058+
create_query_info_future.Release();
1059+
delete query_info;
1060+
}
1061+
9961062
// Interactive test section. These have been placed up front so that the
9971063
// tester doesn't get bored waiting for them.
9981064
TEST_F(FirebaseGmaUITest, TestAdViewAdOpenedAdClosed) {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FIREBASE_GMA_SRC_STUB_QUERY_INFO_INTERNAL_STUB_H_
18+
#define FIREBASE_GMA_SRC_STUB_QUERY_INFO_INTERNAL_STUB_H_
19+
20+
#include "gma/src/common/query_info_internal.h"
21+
22+
namespace firebase {
23+
namespace gma {
24+
namespace internal {
25+
26+
/// Stub version of QueryInfoInternal, for use on desktop platforms. GMA
27+
/// is forbidden on desktop, so this version creates and immediately completes
28+
/// the Future for each method.
29+
class QueryInfoInternalStub : public QueryInfoInternal {
30+
public:
31+
explicit QueryInfoInternalStub(QueryInfo* base) : QueryInfoInternal(base) {}
32+
33+
~QueryInfoInternalStub() override {}
34+
35+
Future<void> Initialize(AdParent parent) override {
36+
return CreateAndCompleteFutureStub(kQueryInfoFnInitialize);
37+
}
38+
39+
Future<QueryInfoResult> CreateQueryInfo(AdFormat format,
40+
const AdRequest& request) override {
41+
return CreateAndCompleteQueryInfoFutureStub(kQueryInfoFnCreateQueryInfo);
42+
}
43+
44+
Future<QueryInfoResult> CreateQueryInfoWithAdUnit(
45+
AdFormat format, const AdRequest& request,
46+
const char* ad_unit_id) override {
47+
return CreateAndCompleteQueryInfoFutureStub(
48+
kQueryInfoFnCreateQueryInfoWithAdUnit);
49+
}
50+
51+
bool is_initialized() const override { return true; }
52+
53+
private:
54+
Future<void> CreateAndCompleteFutureStub(QueryInfoFn fn) {
55+
CreateAndCompleteFuture(fn, kAdErrorCodeNone, nullptr, &future_data_);
56+
return GetLastResult(fn);
57+
}
58+
59+
Future<QueryInfoResult> CreateAndCompleteQueryInfoFutureStub(QueryInfoFn fn) {
60+
return CreateAndCompleteFutureWithQueryInfoResult(
61+
fn, kAdErrorCodeNone, nullptr, &future_data_, QueryInfoResult());
62+
}
63+
};
64+
65+
} // namespace internal
66+
} // namespace gma
67+
} // namespace firebase
68+
69+
#endif // FIREBASE_GMA_SRC_STUB_QUERY_INFO_INTERNAL_STUB_H_

0 commit comments

Comments
 (0)