Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

CDVStartPageTests.m 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. #import <XCTest/XCTest.h>
  18. #import "CDVWebViewTest.h"
  19. #import <Cordova/CDVViewController.h>
  20. #import "AppDelegate.h"
  21. @interface CDVStartPageTestViewController : UIViewController
  22. @property (strong, nonatomic) CDVViewController* vc1;
  23. @property (strong, nonatomic) CDVViewController* vc2;
  24. @end
  25. @implementation CDVStartPageTestViewController
  26. @synthesize vc1 = _vc1, vc2 = _vc2;
  27. - (void)loadView
  28. {
  29. _vc1 = [[CDVViewController alloc] init];
  30. _vc1.wwwFolderName = @"www";
  31. _vc1.startPage = @"index.html";
  32. [self addChildViewController:_vc1];
  33. _vc2 = [[CDVViewController alloc] init];
  34. _vc2.wwwFolderName = @"www";
  35. _vc2.startPage = @"index.html?delta=true";
  36. [self addChildViewController:_vc2];
  37. CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
  38. UIView* contentView = [[UIView alloc] initWithFrame:applicationFrame];
  39. CGRect sub1, sub2;
  40. CGRectDivide(applicationFrame, &sub1, &sub2, applicationFrame.size.height / 2, CGRectMinYEdge);
  41. [_vc1.view setBounds:sub1];
  42. [_vc2.view setBounds:sub2];
  43. [contentView addSubview:_vc1.view];
  44. [contentView addSubview:_vc2.view];
  45. self.view = contentView;
  46. }
  47. @end
  48. @interface CDVStartPageTest : CDVWebViewTest
  49. @end
  50. @implementation CDVStartPageTest
  51. - (void)setUp
  52. {
  53. [super setUp];
  54. }
  55. - (void)tearDown
  56. {
  57. [super tearDown];
  58. }
  59. - (void)testParametersInStartPage
  60. {
  61. XCTestExpectation* expectation1 = [self expectationWithDescription:@"href should point to index.html"];
  62. XCTestExpectation* expectation2 = [self expectationWithDescription:@"href should point to index.html?delta=true"];
  63. CDVStartPageTestViewController* rootVc = [[CDVStartPageTestViewController alloc] init];
  64. self.appDelegate.window.rootViewController = rootVc;
  65. id <CDVWebViewEngineProtocol> vc1WebViewEngine = rootVc.vc1.webViewEngine;
  66. id <CDVWebViewEngineProtocol> vc2WebViewEngine = rootVc.vc2.webViewEngine;
  67. NSString* geHREF = @"window.location.href";
  68. [self waitForConditionName:@"getting href" block:^{
  69. NSURL* vc1URL = vc1WebViewEngine.URL;
  70. NSURL* vc2URL = vc2WebViewEngine.URL;
  71. return
  72. (BOOL)(
  73. (vc1URL != nil && ![[vc1URL absoluteString] isEqualToString:@"about:blank"] && ![[vc1URL absoluteString] isEqualToString:@""]) &&
  74. (vc2URL != nil && ![[vc2URL absoluteString] isEqualToString:@"about:blank"] && ![[vc2URL absoluteString] isEqualToString:@""])
  75. );
  76. }];
  77. [vc1WebViewEngine evaluateJavaScript:geHREF completionHandler:^(NSString* href, NSError* error) {
  78. if (error) {
  79. NSLog(@"error is: %@", error);
  80. } else {
  81. XCTAssertTrue([href hasSuffix:@"index.html"], @"href should point to index.html");
  82. [expectation1 fulfill];
  83. }
  84. }];
  85. [vc2WebViewEngine evaluateJavaScript:geHREF completionHandler:^(NSString* href, NSError* error) {
  86. if (error) {
  87. NSLog(@"error is: %@", error);
  88. } else {
  89. XCTAssertTrue([href hasSuffix:@"index.html?delta=true"], @"href should point to index.html?delta=true");
  90. [expectation2 fulfill];
  91. }
  92. }];
  93. [self waitForExpectationsWithTimeout:5.0 handler:^(NSError* error) {
  94. if (error) {
  95. XCTFail(@"Expectation Failed with error: %@", error);
  96. }
  97. }];
  98. }
  99. @end