// Copyright (c) 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include #include "content/renderer/date_time_formatter.h" #include "content/renderer/renderer_date_time_picker.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserParams.h" #include "third_party/icu/public/common/unicode/unistr.h" #include "ui/base/ime/text_input_type.h" namespace content { class RendererDateTimePickerTest { }; TEST(RendererDateTimePickerTest, TestParserValidStringInputs) { WebKit::WebDateTimeChooserParams params; params.currentValue = "2010-07"; params.type = WebKit::WebDateTimeInputTypeMonth; DateTimeFormatter sut(params); EXPECT_EQ(2010, sut.GetYear()); // Month field is 0 based EXPECT_EQ(6, sut.GetMonth()); // Month input defaults to the first day of the month (1 based) EXPECT_EQ(1, sut.GetDay()); EXPECT_EQ(0, sut.GetHour()); EXPECT_EQ(0, sut.GetMinute()); EXPECT_EQ(0, sut.GetSecond()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_MONTH, sut.GetType()); params.currentValue = "2012-05-25"; params.type = WebKit::WebDateTimeInputTypeDate; DateTimeFormatter sut2(params); EXPECT_EQ(2012, sut2.GetYear()); EXPECT_EQ(4, sut2.GetMonth()); EXPECT_EQ(25, sut2.GetDay()); EXPECT_EQ(0, sut2.GetHour()); EXPECT_EQ(0, sut2.GetMinute()); EXPECT_EQ(0, sut2.GetSecond()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_DATE, sut2.GetType()); params.currentValue = "2013-05-21T12:15"; params.type = WebKit::WebDateTimeInputTypeDateTimeLocal; DateTimeFormatter sut3(params); EXPECT_EQ(2013, sut3.GetYear()); EXPECT_EQ(4, sut3.GetMonth()); EXPECT_EQ(21, sut3.GetDay()); EXPECT_EQ(12, sut3.GetHour()); EXPECT_EQ(15, sut3.GetMinute()); EXPECT_EQ(0, sut3.GetSecond()); EXPECT_EQ(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, sut3.GetType()); } TEST(RendererDateTimePickerTest, TestParserInvalidStringInputs) { // Random non parsable text WebKit::WebDateTimeChooserParams params; params.currentValue = "