Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp

Issue 2045833002: Add 'selected' boolean to 'ShippingOption' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp
index f5ea8a1e4d75a4e082d93ed7bcd863783233e7fe..d88fb65d674dfdf6070b81b6eac933a5c9782cf3 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp
@@ -103,11 +103,50 @@ TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable)
EXPECT_TRUE(request->shippingOption().isNull());
}
-TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingRequested)
+TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault)
{
PaymentDetails details;
details.setTotal(buildPaymentItemForTest());
details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard")));
+
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState());
+
+ EXPECT_TRUE(request->shippingOption().isNull());
+}
+
+TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNotRequested)
+{
+ PaymentDetails details;
+ details.setTotal(buildPaymentItemForTest());
+ details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOptionForTest()));
+ PaymentOptions options;
+ options.setRequestShipping(false);
+
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, options, getExceptionState());
+
+ EXPECT_TRUE(request->shippingOption().isNull());
+}
+
+TEST_F(PaymentRequestTest, DontSelectSingleUnselectedShippingOptionWhenShippingRequested)
+{
+ PaymentDetails details;
+ details.setTotal(buildPaymentItemForTest());
+ details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOptionForTest()));
+ PaymentOptions options;
+ options.setRequestShipping(true);
+
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, options, getExceptionState());
+
+ EXPECT_TRUE(request->shippingOption().isNull());
+}
+
+TEST_F(PaymentRequestTest, SelectSingleSelectedShippingOptionWhenShippingRequested)
+{
+ PaymentDetails details;
+ details.setTotal(buildPaymentItemForTest());
+ HeapVector<ShippingOption> shippingOptions(1, buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"));
+ shippingOptions[0].setSelected(true);
+ details.setShippingOptions(shippingOptions);
PaymentOptions options;
options.setRequestShipping(true);
@@ -116,28 +155,39 @@ TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques
EXPECT_EQ("standard", request->shippingOption());
}
-TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault)
+TEST_F(PaymentRequestTest, SelectOnlySelectedShippingOptionWhenShippingRequested)
{
PaymentDetails details;
details.setTotal(buildPaymentItemForTest());
- details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard")));
+ HeapVector<ShippingOption> shippingOptions(2);
+ shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard");
+ shippingOptions[0].setSelected(true);
+ shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "express");
+ details.setShippingOptions(shippingOptions);
+ PaymentOptions options;
+ options.setRequestShipping(true);
- PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState());
+ PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, options, getExceptionState());
- EXPECT_TRUE(request->shippingOption().isNull());
+ EXPECT_EQ("standard", request->shippingOption());
}
-TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNotRequested)
+TEST_F(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested)
{
PaymentDetails details;
details.setTotal(buildPaymentItemForTest());
- details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOptionForTest()));
+ HeapVector<ShippingOption> shippingOptions(2);
+ shippingOptions[0] = buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard");
+ shippingOptions[0].setSelected(true);
+ shippingOptions[1] = buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, "express");
+ shippingOptions[1].setSelected(true);
+ details.setShippingOptions(shippingOptions);
PaymentOptions options;
- options.setRequestShipping(false);
+ options.setRequestShipping(true);
PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, options, getExceptionState());
- EXPECT_TRUE(request->shippingOption().isNull());
+ EXPECT_EQ("express", request->shippingOption());
}
TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow)
@@ -399,7 +449,7 @@ TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
EXPECT_TRUE(request->shippingOption().isNull());
request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectNoCall(getScriptState()));
String detailWithShippingOptions = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}},"
- "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]}";
+ "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}, \"selected\": true}]}";
request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSONString(getScriptState(), detailWithShippingOptions, getExceptionState())));
EXPECT_FALSE(getExceptionState().hadException());
EXPECT_EQ("standardShippingOption", request->shippingOption());
@@ -411,7 +461,7 @@ TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
EXPECT_TRUE(request->shippingOption().isNull());
}
-TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultipleShippingOptions)
+TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultipleUnselectedShippingOptions)
{
ScriptState::Scope scope(getScriptState());
PaymentOptions options;
@@ -429,7 +479,7 @@ TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
EXPECT_TRUE(request->shippingOption().isNull());
}
-TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate)
+TEST_F(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate)
{
ScriptState::Scope scope(getScriptState());
PaymentOptions options;
@@ -438,12 +488,13 @@ TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate)
EXPECT_FALSE(getExceptionState().hadException());
request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectNoCall(getScriptState()));
String detail = "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}},"
- "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]}";
+ "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}},"
+ "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"USD\", \"value\": \"50.00\"}, \"selected\": true}]}";
request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSONString(getScriptState(), detail, getExceptionState())));
EXPECT_FALSE(getExceptionState().hadException());
- EXPECT_EQ("standardShippingOption", request->shippingOption());
+ EXPECT_EQ("fast", request->shippingOption());
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698